Changeset - r17251:1a6731d06266
[Not reviewed]
master
0 7 0
alberth - 14 years ago 2011-02-06 18:26:50
alberth@openttd.org
(svn r22001) -Codechange: Rename difficulty.number_industries to difficulty.industry_density.
7 files changed with 20 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/genworld_gui.cpp
Show inline comments
 
@@ -345,97 +345,97 @@ struct GenerateLandscapeWindow : public 
 
	uint widget_id;
 
	uint x;
 
	uint y;
 
	char name[64];
 
	GenenerateLandscapeWindowMode mode;
 

	
 
	GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11)
 
	{
 
		this->InitNested(desc, number);
 

	
 
		this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
 

	
 
		/* snprintf() always outputs trailing '\0', so whole buffer can be used */
 
		snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
 
		this->caption = STR_NULL;
 
		this->afilter = CS_NUMERAL;
 

	
 
		this->mode = (GenenerateLandscapeWindowMode)this->window_number;
 

	
 
		/* Disable town, industry and trees in SE */
 
		this->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
 
		this->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
 
		this->SetWidgetDisabledState(GLAND_TREE_PULLDOWN,     _game_mode == GM_EDITOR);
 

	
 
		this->OnInvalidateData();
 
	}
 

	
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case GLAND_START_DATE_TEXT:     SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
 
			case GLAND_MAPSIZE_X_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
 
			case GLAND_MAPSIZE_Y_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
 
			case GLAND_SNOW_LEVEL_TEXT:     SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
 

	
 
			case GLAND_TOWN_PULLDOWN:
 
				if (_game_mode == GM_EDITOR) {
 
					SetDParam(0, STR_DISASTERS_OFF);
 
				} else if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
 
					SetDParam(0, STR_NUM_CUSTOM_NUMBER);
 
					SetDParam(1, _settings_newgame.game_creation.custom_town_number);
 
				} else {
 
					SetDParam(0, _num_towns[_settings_newgame.difficulty.number_towns]);
 
				}
 
				break;
 

	
 
			case GLAND_INDUSTRY_PULLDOWN:   SetDParam(0, _game_mode == GM_EDITOR ? STR_DISASTERS_OFF : _num_inds[_settings_newgame.difficulty.number_industries]); break;
 
			case GLAND_INDUSTRY_PULLDOWN:   SetDParam(0, _game_mode == GM_EDITOR ? STR_DISASTERS_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
 
			case GLAND_LANDSCAPE_PULLDOWN:  SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
 
			case GLAND_TREE_PULLDOWN:       SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
 
			case GLAND_TERRAIN_PULLDOWN:    SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
 

	
 
			case GLAND_WATER_PULLDOWN:
 
				if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
					SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
 
					SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
 
				} else {
 
					SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
 
				}
 
				break;
 

	
 
			case GLAND_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
 
			case GLAND_VARIETY_PULLDOWN:    SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
 
			case GLAND_BORDERS_RANDOM:      SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
 
			case GLAND_WATER_NE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
 
			case GLAND_WATER_NW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
 
			case GLAND_WATER_SE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
 
			case GLAND_WATER_SW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
 
			case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
 

	
 
			case GLAND_HEIGHTMAP_SIZE_TEXT:
 
				if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
 
					SetDParam(0, this->y);
 
					SetDParam(1, this->x);
 
				} else {
 
					SetDParam(0, this->x);
 
					SetDParam(1, this->y);
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data = 0)
 
	{
 
		/* Update the climate buttons */
 
		this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
 
		this->SetWidgetLoweredState(GLAND_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
 
		this->SetWidgetLoweredState(GLAND_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
 
		this->SetWidgetLoweredState(GLAND_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
 

	
 
		/* You can't select smoothness / non-water borders if not terragenesis */
 
		if (mode == GLWM_GENERATE) {
 
			this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
 
			this->SetWidgetDisabledState(GLAND_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
 
			this->SetWidgetDisabledState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
 
			this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
 
@@ -541,97 +541,97 @@ struct GenerateLandscapeWindow : public 
 
		size->width += padding.width;
 
		size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case GLAND_HEIGHTMAP_NAME_TEXT: {
 
				/* Little bit of a hack going on here; just to get the widgets
 
				 * spaced without doing much magic. The space we can draw on is
 
				 * covered by both the spacer and text widgets, so take their
 
				 * outer most boundaries (left and right) as draw locations. */
 
				const NWidgetBase *nwi_spacer = this->GetWidget<NWidgetBase>(GLAND_HEIGHTMAP_NAME_SPACER);
 
				DrawString(min(r.left, nwi_spacer->pos_x), max<int>(r.right, nwi_spacer->pos_x + nwi_spacer->current_x), r.top, this->name, TC_ORANGE);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		this->DrawEditBox(GLAND_RANDOM_EDITBOX);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case GLAND_TEMPERATE:
 
			case GLAND_ARCTIC:
 
			case GLAND_TROPICAL:
 
			case GLAND_TOYLAND:
 
				SetNewLandscapeType(widget - GLAND_TEMPERATE);
 
				break;
 

	
 
			case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X
 
				ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, GLAND_MAPSIZE_X_PULLDOWN);
 
				break;
 

	
 
			case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y
 
				ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
 
				break;
 

	
 
			case GLAND_TOWN_PULLDOWN: // Number of towns
 
				ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
 
				break;
 

	
 
			case GLAND_INDUSTRY_PULLDOWN: // Number of industries
 
				ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.number_industries, GLAND_INDUSTRY_PULLDOWN, 0, 0);
 
				ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, GLAND_INDUSTRY_PULLDOWN, 0, 0);
 
				break;
 

	
 
			case GLAND_RANDOM_BUTTON: // Random seed
 
				_settings_newgame.game_creation.generation_seed = InteractiveRandom();
 
				snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
 
				UpdateTextBufferSize(&this->text);
 
				this->SetDirty();
 
				break;
 

	
 
			case GLAND_GENERATE_BUTTON: // Generate
 
				MakeNewgameSettingsLive();
 

	
 
				if (mode == GLWM_HEIGHTMAP &&
 
						(this->x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
 
						this->x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
 
						this->y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
 
						this->y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
 
					ShowQuery(
 
						STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
 
						STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
 
						this,
 
						LandscapeGenerationCallback);
 
				} else {
 
					StartGeneratingLandscape(mode);
 
				}
 
				break;
 

	
 
			case GLAND_START_DATE_DOWN:
 
			case GLAND_START_DATE_UP: // Year buttons
 
				/* Don't allow too fast scrolling */
 
				if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
 
					this->HandleButtonClick(widget);
 

	
 
					_settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
 
					this->InvalidateData();
 
				}
 
				_left_button_clicked = false;
 
				break;
 

	
 
			case GLAND_START_DATE_TEXT: // Year text
 
				this->widget_id = GLAND_START_DATE_TEXT;
 
				SetDParam(0, _settings_newgame.game_creation.starting_year);
 
				ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
 
				break;
 

	
 
			case GLAND_SNOW_LEVEL_DOWN:
 
			case GLAND_SNOW_LEVEL_UP: // Snow line buttons
 
				/* Don't allow too fast scrolling */
 
@@ -716,97 +716,97 @@ struct GenerateLandscapeWindow : public 
 
	{
 
		static const int raise_widgets[] = {GLAND_START_DATE_DOWN, GLAND_START_DATE_UP, GLAND_SNOW_LEVEL_UP, GLAND_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
 
		for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
 
			if (this->IsWidgetLowered(*widget)) {
 
				this->RaiseWidget(*widget);
 
				this->SetWidgetDirty(*widget);
 
			}
 
		}
 
	}
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(GLAND_RANDOM_EDITBOX);
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
 
		/* the seed is unsigned, therefore atoi cannot be used.
 
		 * As UINT32_MAX is a 'magic' value (use random seed) it
 
		 * should not be possible to be entered into the input
 
		 * field; the generate seed button can be used instead. */
 
		_settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
 
		return state;
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
 
			case GLAND_MAPSIZE_X_PULLDOWN:     _settings_newgame.game_creation.map_x = index; break;
 
			case GLAND_MAPSIZE_Y_PULLDOWN:     _settings_newgame.game_creation.map_y = index; break;
 
			case GLAND_TREE_PULLDOWN:          _settings_newgame.game_creation.tree_placer = index; break;
 
			case GLAND_SMOOTHNESS_PULLDOWN:    _settings_newgame.game_creation.tgen_smoothness = index;  break;
 
			case GLAND_VARIETY_PULLDOWN:       _settings_newgame.game_creation.variety = index; break;
 
			case GLAND_LANDSCAPE_PULLDOWN:     _settings_newgame.game_creation.land_generator = index; break;
 
			case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
 

	
 
			case GLAND_TOWN_PULLDOWN:
 
				if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
 
					this->widget_id = widget;
 
					SetDParam(0, _settings_newgame.game_creation.custom_town_number);
 
					ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, 50, this, CS_NUMERAL, QSF_NONE);
 
				}
 
				IConsoleSetSetting("difficulty.number_towns", index);
 
				break;
 

	
 
			case GLAND_INDUSTRY_PULLDOWN:
 
				IConsoleSetSetting("difficulty.number_industries", index);
 
				IConsoleSetSetting("difficulty.industry_density", index);
 
				break;
 

	
 
			case GLAND_TERRAIN_PULLDOWN: {
 
				GameMode old_gm = _game_mode;
 
				_game_mode = GM_MENU;
 
				IConsoleSetSetting("difficulty.terrain_type", index);
 
				_game_mode = old_gm;
 
				break;
 
			}
 

	
 
			case GLAND_WATER_PULLDOWN: {
 
				if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
					this->widget_id = widget;
 
					SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
 
					ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, 50, this, CS_NUMERAL, QSF_NONE);
 
				}
 
				GameMode old_gm = _game_mode;
 
				_game_mode = GM_MENU;
 
				IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
 
				_game_mode = old_gm;
 
				break;
 
			}
 
		}
 
		this->InvalidateData();
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		/* Was 'cancel' pressed? */
 
		if (str == NULL) return;
 

	
 
		int32 value;
 
		if (!StrEmpty(str)) {
 
			value = atoi(str);
 
		} else {
 
			/* An empty string means revert to the default */
 
			switch (this->widget_id) {
 
				case GLAND_START_DATE_TEXT: value = DEF_START_YEAR; break;
 
				case GLAND_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
 
				case GLAND_TOWN_PULLDOWN:   value = 1; break;
 
				case GLAND_WATER_PULLDOWN:  value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
 
				default: NOT_REACHED();
 
			}
 
		}
 

	
 
		switch (this->widget_id) {
 
			case GLAND_START_DATE_TEXT:
 
				this->SetWidgetDirty(GLAND_START_DATE_TEXT);
src/industry_cmd.cpp
Show inline comments
 
@@ -1802,260 +1802,260 @@ CommandCost CmdBuildIndustry(TileIndex t
 
	if ((flags & DC_EXEC) && ind != NULL && _game_mode != GM_EDITOR) {
 
		/* Created a new industry in-game, advertise the event. */
 
		SetDParam(0, indspec->name);
 
		if (indspec->new_industry_text > STR_LAST_STRINGID) {
 
			SetDParam(1, STR_TOWN_NAME);
 
			SetDParam(2, ind->town->index);
 
		} else {
 
			SetDParam(1, ind->town->index);
 
		}
 
		AddIndustryNewsItem(indspec->new_industry_text, NS_INDUSTRY_OPEN, ind->index);
 
		AI::BroadcastNewEvent(new AIEventIndustryOpen(ind->index));
 
	}
 

	
 
	return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
 
}
 

	
 

	
 
/**
 
 * Create a new industry of random layout.
 
 * @param tile The location to build the industry.
 
 * @param type The industry type to build.
 
 * @param creation_type The circumstances the industry is created under.
 
 * @return the created industry or NULL if it failed.
 
 */
 
static Industry *CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 

	
 
	uint32 seed = Random();
 
	uint32 seed2 = Random();
 
	Industry *i = NULL;
 
	CommandCost ret = CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
 
	assert(i != NULL || ret.Failed());
 
	return i;
 
}
 

	
 
/**
 
 * Compute the appearance probability for an industry during map creation.
 
 * @param it Industry type to compute.
 
 * @param [out] force_at_least_one Returns whether at least one instance should be forced on map creation.
 
 * @return Relative probability for the industry to appear.
 
 */
 
static uint32 GetScaledIndustryGenerationProbability(IndustryType it, bool *force_at_least_one)
 
{
 
	const IndustrySpec *ind_spc = GetIndustrySpec(it);
 
	uint32 chance = ind_spc->appear_creation[_settings_game.game_creation.landscape] * 16; // * 16 to increase precision
 
	if (!ind_spc->enabled || chance == 0 || ind_spc->num_table == 0 ||
 
			!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION) ||
 
			(_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == ID_FUND_ONLY)) {
 
			(_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == ID_FUND_ONLY)) {
 
		*force_at_least_one = false;
 
		return 0;
 
	} else {
 
		/* We want industries appearing at coast to appear less often on bigger maps, as length of coast increases slower than map area.
 
		 * For simplicity we scale in both cases, though scaling the probabilities of all industries has no effect. */
 
		chance = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(chance) : ScaleByMapSize(chance);
 

	
 
		*force_at_least_one = (chance > 0) && !(ind_spc->behaviour & INDUSTRYBEH_NOBUILT_MAPCREATION) && (_game_mode != GM_EDITOR);
 
		return chance;
 
	}
 
}
 

	
 
/**
 
 * Compute the probability for constructing a new industry during game play.
 
 * @param it Industry type to compute.
 
 * @param [out] min_number Minimal number of industries that should exist at the map.
 
 * @return Relative probability for the industry to appear.
 
 */
 
static uint16 GetIndustryGamePlayProbability(IndustryType it, byte *min_number)
 
{
 
	if (_settings_game.difficulty.number_industries == ID_FUND_ONLY) {
 
	if (_settings_game.difficulty.industry_density == ID_FUND_ONLY) {
 
		*min_number = 0;
 
		return 0;
 
	}
 

	
 
	const IndustrySpec *ind_spc = GetIndustrySpec(it);
 
	byte chance = ind_spc->appear_ingame[_settings_game.game_creation.landscape];
 
	if (!ind_spc->enabled || chance == 0 || ind_spc->num_table == 0 ||
 
			((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) ||
 
			((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) ||
 
			!CheckIfCallBackAllowsAvailability(it, IACT_RANDOMCREATION)) {
 
		*min_number = 0;
 
		return 0;
 
	}
 
	*min_number = (ind_spc->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) ? 1 : 0;
 
	return chance;
 
}
 

	
 
/**
 
 * Get wanted number of industries on the map.
 
 * @return Wanted number of industries at the map.
 
 */
 
static uint GetNumberOfIndustries()
 
{
 
	/* Number of industries on a 256x256 map. */
 
	static const uint16 numof_industry_table[] = {
 
		0,    // none
 
		0,    // minimal
 
		10,   // very low
 
		25,   // low
 
		55,   // normal
 
		80,   // high
 
	};
 

	
 
	assert(lengthof(numof_industry_table) == ID_END);
 
	uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_industries : (uint)ID_VERY_LOW;
 
	uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW;
 
	return ScaleByMapSize(numof_industry_table[difficulty]);
 
}
 

	
 
/**
 
 * Advertise about a new industry opening.
 
 * @param ind Industry being opened.
 
 */
 
static void AdvertiseIndustryOpening(const Industry *ind)
 
{
 
	const IndustrySpec *ind_spc = GetIndustrySpec(ind->type);
 
	SetDParam(0, ind_spc->name);
 
	if (ind_spc->new_industry_text > STR_LAST_STRINGID) {
 
		SetDParam(1, STR_TOWN_NAME);
 
		SetDParam(2, ind->town->index);
 
	} else {
 
		SetDParam(1, ind->town->index);
 
	}
 
	AddIndustryNewsItem(ind_spc->new_industry_text, NS_INDUSTRY_OPEN, ind->index);
 
	AI::BroadcastNewEvent(new AIEventIndustryOpen(ind->index));
 
}
 

	
 
/**
 
 * Try to place the industry in the game.
 
 * Since there is no feedback why placement fails, there is no other option
 
 * than to try a few times before concluding it does not work.
 
 * @param type     Industry type of the desired industry.
 
 * @param try_hard Try very hard to find a place. (Used to place at least one industry per type.)
 
 * @return Pointer to created industry, or \c NULL if creation failed.
 
 */
 
static Industry *PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
 
{
 
	uint tries = try_hard ? 10000u : 2000u;
 
	for (; tries > 0; tries--) {
 
		Industry *ind = CreateNewIndustry(RandomTile(), type, creation_type);
 
		if (ind != NULL) return ind;
 
	}
 
	return NULL;
 
}
 

	
 
/**
 
 * Try to build a industry on the map.
 
 * @param type IndustryType of the desired industry
 
 * @param try_hard Try very hard to find a place. (Used to place at least one industry per type)
 
 */
 
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
 
{
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
	IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
 
	PlaceIndustry(type, IACT_MAPGENERATION, try_hard);
 

	
 
	cur_company.Restore();
 
}
 

	
 
/**
 
 * Get total number of industries existing in the game.
 
 * @return Number of industries currently in the game.
 
 */
 
static uint GetCurrentTotalNumberOfIndustries()
 
{
 
	int total = 0;
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) total += Industry::GetIndustryTypeCount(it);
 
	return total;
 
}
 

	
 

	
 
/** Reset the entry. */
 
void IndustryTypeBuildData::Reset()
 
{
 
	this->probability  = 0;
 
	this->min_number   = 0;
 
	this->target_count = 0;
 
	this->max_wait     = 1;
 
	this->wait_count   = 0;
 
}
 

	
 
/** Completely reset the industry build data. */
 
void IndustryBuildData::Reset()
 
{
 
	this->wanted_inds = GetCurrentTotalNumberOfIndustries() << 16;
 

	
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		this->builddata[it].Reset();
 
	}
 
}
 

	
 
/** Monthly update of industry build data. */
 
void IndustryBuildData::MonthlyLoop()
 
{
 
	static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12); // lower 16 bits is a float fraction, 3.5 industries per decade, divided by 10 * 12 months.
 
	if (_settings_game.difficulty.number_industries == ID_FUND_ONLY) return; // 'no industries' setting,
 
	if (_settings_game.difficulty.industry_density == ID_FUND_ONLY) return; // 'no industries' setting,
 

	
 
	/* To prevent running out of unused industries for the player to connect,
 
	 * add a fraction of new industries each month, but only if the manager can keep up. */
 
	uint max_behind = 1 + min(99u, ScaleByMapSize(3)); // At most 2 industries for small maps, and 100 at the biggest map (about 6 months industry build attempts).
 
	if (GetCurrentTotalNumberOfIndustries() + max_behind >= (this->wanted_inds >> 16)) {
 
		this->wanted_inds += ScaleByMapSize(NEWINDS_PER_MONTH);
 
	}
 
}
 

	
 
/**
 
 * This function will create random industries during game creation.
 
 * It will scale the amount of industries by mapsize and difficulty level.
 
 */
 
void GenerateIndustries()
 
{
 
	if (_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == ID_FUND_ONLY) return; // No industries in the game.
 
	if (_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == ID_FUND_ONLY) return; // No industries in the game.
 

	
 
	uint32 industry_probs[NUM_INDUSTRYTYPES];
 
	bool force_at_least_one[NUM_INDUSTRYTYPES];
 
	uint32 total_prob = 0;
 
	uint num_forced = 0;
 

	
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		industry_probs[it] = GetScaledIndustryGenerationProbability(it, force_at_least_one + it);
 
		total_prob += industry_probs[it];
 
		if (force_at_least_one[it]) num_forced++;
 
	}
 

	
 
	uint total_amount = GetNumberOfIndustries();
 
	if (total_prob == 0 || total_amount < num_forced) {
 
		/* Only place the forced ones */
 
		total_amount = num_forced;
 
	}
 

	
 
	SetGeneratingWorldProgress(GWP_INDUSTRY, total_amount);
 

	
 
	/* Try to build one industry per type independent of any probabilities */
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		if (force_at_least_one[it]) {
 
			assert(total_amount > 0);
 
			total_amount--;
 
			PlaceInitialIndustry(it, true);
 
		}
 
	}
 

	
 
	/* Add the remaining industries according to their probabilities */
 
	for (uint i = 0; i < total_amount; i++) {
 
		uint32 r = RandomRange(total_prob);
 
		IndustryType it = 0;
 
		while (r >= industry_probs[it]) {
 
			r -= industry_probs[it];
 
			it++;
 
			assert(it < NUM_INDUSTRYTYPES);
 
		}
 
		assert(industry_probs[it] > 0);
 
		PlaceInitialIndustry(it, false);
 
	}
 
	_industry_builder.Reset();
 
}
 

	
 
/**
 
 * Monthly update of industry statistics.
 
 * @param i Industry to update.
 
 */
src/industry_gui.cpp
Show inline comments
 
@@ -557,97 +557,97 @@ public:
 
			_generating_world = false;
 
		} else {
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (!this->timer_enabled) return;
 
		if (--this->callback_timer == 0) {
 
			/* We have just passed another day.
 
			 * See if we need to update availability of currently selected industry */
 
			this->callback_timer = DAY_TICKS; // restart counter
 

	
 
			const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
 

	
 
			if (indsp->enabled) {
 
				bool call_back_result = CheckIfCallBackAllowsAvailability(this->selected_type, IACT_USERCREATION);
 

	
 
				/* Only if result does match the previous state would it require a redraw. */
 
				if (call_back_result != this->enabled[this->selected_index]) {
 
					this->enabled[this->selected_index] = call_back_result;
 
					this->SetButtons();
 
					this->SetDirty();
 
				}
 
			}
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		this->RaiseButtons();
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
 
	{
 
		this->RaiseButtons();
 
	}
 

	
 
	virtual void OnInvalidateData(int data = 0)
 
	{
 
		this->SetupArrays();
 

	
 
		const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
 
		if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.number_industries != ID_FUND_ONLY;
 
		if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.industry_density != ID_FUND_ONLY;
 
		this->SetButtons();
 
	}
 
};
 

	
 
void ShowBuildIndustryWindow()
 
{
 
	if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
 
	if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
 
	new BuildIndustryWindow();
 
}
 

	
 
static void UpdateIndustryProduction(Industry *i);
 

	
 
static inline bool IsProductionAlterable(const Industry *i)
 
{
 
	const IndustrySpec *is = GetIndustrySpec(i->type);
 
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
 
			(is->production_rate[0] != 0 || is->production_rate[1] != 0 || is->IsRawIndustry()));
 
}
 

	
 
/** Names of the widgets of the view industry gui */
 
enum IndustryViewWidgets {
 
	IVW_CAPTION,
 
	IVW_VIEWPORT,
 
	IVW_INFO,
 
	IVW_GOTO,
 
	IVW_DISPLAY,
 
};
 

	
 
class IndustryViewWindow : public Window
 
{
 
	/** Modes for changing production */
 
	enum Editability {
 
		EA_NONE,              ///< Not alterable
 
		EA_MULTIPLIER,        ///< Allow changing the production multiplier
 
		EA_RATE,              ///< Allow changing the production rates
 
	};
 

	
 
	/** Specific lines in the info panel */
 
	enum InfoLine {
 
		IL_NONE,              ///< No line
 
		IL_MULTIPLIER,        ///< Production multiplier
 
		IL_RATE1,             ///< Production rate of cargo 1
 
		IL_RATE2,             ///< Production rate of cargo 2
 
	};
 

	
 
	Editability editable;     ///< Mode for changing production
 
	InfoLine editbox_line;    ///< The line clicked to open the edit box
src/saveload/afterload.cpp
Show inline comments
 
@@ -1403,100 +1403,100 @@ bool AfterLoadGame()
 
			if (IsStatueTile(t)) {
 
				_m[t].m2 = CalcClosestTownFromTile(t)->index;
 
			}
 
		}
 
	}
 

	
 
	/* A setting containing the proportion of towns that grow twice as
 
	 * fast was added in version 54. From version 56 this is now saved in the
 
	 * town as cities can be built specifically in the scenario editor. */
 
	if (IsSavegameVersionBefore(56)) {
 
		Town *t;
 

	
 
		FOR_ALL_TOWNS(t) {
 
			if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
 
				t->larger_town = true;
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(57)) {
 
		Vehicle *v;
 
		/* Added a FIFO queue of vehicles loading at stations */
 
		FOR_ALL_VEHICLES(v) {
 
			if ((v->type != VEH_TRAIN || Train::From(v)->IsFrontEngine()) &&  // for all locs
 
					!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
 
					v->current_order.IsType(OT_LOADING)) {         // loading
 
				Station::Get(v->last_station_visited)->loading_vehicles.push_back(v);
 

	
 
				/* The loading finished flag is *only* set when actually completely
 
				 * finished. Because the vehicle is loading, it is not finished. */
 
				ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
 
			}
 
		}
 
	} else if (IsSavegameVersionBefore(59)) {
 
		/* For some reason non-loading vehicles could be in the station's loading vehicle list */
 

	
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			std::list<Vehicle *>::iterator iter;
 
			for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
 
				Vehicle *v = *iter;
 
				iter++;
 
				if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(58)) {
 
		/* Setting difficulty number_industries other than zero get bumped to +1
 
		 * since a new option (very low at position1) has been added */
 
		if (_settings_game.difficulty.number_industries > 0) {
 
			_settings_game.difficulty.number_industries++;
 
		/* Setting difficulty industry_density other than zero get bumped to +1
 
		 * since a new option (very low at position 1) has been added */
 
		if (_settings_game.difficulty.industry_density > 0) {
 
			_settings_game.difficulty.industry_density++;
 
		}
 

	
 
		/* Same goes for number of towns, although no test is needed, just an increment */
 
		_settings_game.difficulty.number_towns++;
 
	}
 

	
 
	if (IsSavegameVersionBefore(64)) {
 
		/* copy the signal type/variant and move signal states bits */
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
 
				SetSignalStates(t, GB(_m[t].m2, 4, 4));
 
				SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
 
				SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
 
				ClrBit(_m[t].m2, 7);
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(69)) {
 
		/* In some old savegames a bit was cleared when it should not be cleared */
 
		RoadVehicle *rv;
 
		FOR_ALL_ROADVEHICLES(rv) {
 
			if (rv->state == 250 || rv->state == 251) {
 
				SetBit(rv->state, 2);
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(70)) {
 
		/* Added variables to support newindustries */
 
		Industry *i;
 
		FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
 
	}
 

	
 
	/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
 
	    Replace the owner for those by OWNER_NONE. */
 
	if (IsSavegameVersionBefore(82)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (IsTileType(t, MP_WATER) &&
 
					GetWaterTileType(t) == WATER_TILE_CLEAR &&
 
					GetTileOwner(t) == OWNER_WATER &&
 
					TileHeight(t) != 0) {
 
				SetTileOwner(t, OWNER_NONE);
 
			}
 
		}
 
	}
 

	
 
	/*
 
@@ -2518,98 +2518,98 @@ bool AfterLoadGame()
 
				case VEH_SHIP:
 
					break;
 

	
 
				default:
 
					continue;
 
			}
 

	
 
			if (IsBridgeTile(v->tile) && TileVirtXY(v->x_pos, v->y_pos) == v->tile) {
 
				/* In old versions, z_pos was 1 unit lower on bridge heads.
 
				 * However, this invalid state could be converted to new savegames
 
				 * by loading and saving the game in a new version. */
 
				v->z_pos = GetSlopeZ(v->x_pos, v->y_pos);
 
				DiagDirection dir = GetTunnelBridgeDirection(v->tile);
 
				if (v->type == VEH_TRAIN && !(v->vehstatus & VS_CRASHED) &&
 
						v->direction != DiagDirToDir(dir)) {
 
					/* If the train has left the bridge, it shouldn't have
 
					 * track == TRACK_BIT_WORMHOLE - this could happen
 
					 * when the train was reversed while on the last "tick"
 
					 * on the ramp before leaving the ramp to the bridge. */
 
					Train::From(v)->track = DiagDirToDiagTrackBits(dir);
 
				}
 
			}
 

	
 
			/* If the vehicle is really above v->tile (not in a wormhole),
 
			 * it should have set v->z_pos correctly. */
 
			assert(v->tile != TileVirtXY(v->x_pos, v->y_pos) || v->z_pos == GetSlopeZ(v->x_pos, v->y_pos));
 
		}
 

	
 
		/* Fill Vehicle::cur_real_order_index */
 
		FOR_ALL_VEHICLES(v) {
 
			if (!v->IsPrimaryVehicle()) continue;
 

	
 
			v->cur_real_order_index = v->cur_auto_order_index;
 
			v->UpdateRealOrderIndex();
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(159)) {
 
		/* If the savegame is old (before version 100), then the value of 255
 
		 * for these settings did not mean "disabled". As such everything
 
		 * before then did reverse.
 
		 * To simplify stuff we disable all turning around or we do not
 
		 * disable anything at all. So, if some reversing was disabled we
 
		 * will keep reversing disabled, otherwise it'll be turned on. */
 
		_settings_game.pf.reverse_at_signals = IsSavegameVersionBefore(100) || (_settings_game.pf.wait_oneway_signal != 255 && _settings_game.pf.wait_twoway_signal != 255 && _settings_game.pf.wait_for_pbs_path != 255);
 
	}
 

	
 
	if (IsSavegameVersionBefore(160)) {
 
		/* Setting difficulty number_industries other than zero get bumped to +1
 
		 * since a new option (very low at position1) has been added */
 
		if (_settings_game.difficulty.number_industries > 0) {
 
			_settings_game.difficulty.number_industries++;
 
		/* Setting difficulty industry_density other than zero get bumped to +1
 
		 * since a new option (minimal at position 1) has been added */
 
		if (_settings_game.difficulty.industry_density > 0) {
 
			_settings_game.difficulty.industry_density++;
 
		}
 
	}
 

	
 
	/* Road stops is 'only' updating some caches */
 
	AfterLoadRoadStops();
 
	AfterLoadLabelMaps();
 

	
 
	GamelogPrintDebug(1);
 

	
 
	InitializeWindowsAndCaches();
 
	/* Restore the signals */
 
	ResetSignalHandlers();
 
	return true;
 
}
 

	
 
/**
 
 * Reload all NewGRF files during a running game. This is a cut-down
 
 * version of AfterLoadGame().
 
 * XXX - We need to reset the vehicle position hash because with a non-empty
 
 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles()
 
 * to recalculate vehicle data as some NewGRF vehicle sets could have been
 
 * removed or added and changed statistics
 
 */
 
void ReloadNewGRFData()
 
{
 
	/* reload grf data */
 
	GfxLoadSprites();
 
	LoadStringWidthTable();
 
	RecomputePrices();
 
	/* reload vehicles */
 
	ResetVehiclePosHash();
 
	AfterLoadVehicles(false);
 
	StartupEngines();
 
	SetCachedEngineCounts();
 
	/* update station graphics */
 
	AfterLoadStations();
 
	/* Check and update house and town values */
 
	UpdateHousesAndTowns();
 
	/* Delete news referring to no longer existing entities */
 
	DeleteInvalidEngineNews();
 
	/* Update livery selection windows */
 
	for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOUR, i);
 
	/* redraw the whole screen */
 
	MarkWholeScreenDirty();
 
	CheckTrainsLengths();
 
}
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -1399,97 +1399,97 @@ static const OldChunks engine_chunk[] = 
 
	OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
 
	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
 
	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
 

	
 
	OCL_NULL( 1 ), // lifelength
 
	OCL_SVAR(  OC_UINT8, Engine, flags ),
 
	OCL_SVAR(  OC_UINT8, Engine, preview_company_rank ),
 
	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
 

	
 
	OCL_CNULL( OC_TTD, 2 ), ///< railtype + junk
 

	
 
	OCL_END()
 
};
 

	
 
static bool LoadOldEngine(LoadgameState *ls, int num)
 
{
 
	Engine *e = _savegame_type == SGT_TTO ? &_old_engines[num] : GetTempDataEngine(num);
 
	return LoadChunk(ls, e, engine_chunk);
 
}
 

	
 
static bool LoadOldEngineName(LoadgameState *ls, int num)
 
{
 
	Engine *e = GetTempDataEngine(num);
 
	e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
 
	return true;
 
}
 

	
 
static const OldChunks subsidy_chunk[] = {
 
	OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
 
	OCL_SVAR(  OC_UINT8, Subsidy, remaining ),
 
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, src ),
 
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, dst ),
 

	
 
	OCL_END()
 
};
 

	
 
static bool LoadOldSubsidy(LoadgameState *ls, int num)
 
{
 
	Subsidy *s = new (num) Subsidy();
 
	bool ret = LoadChunk(ls, s, subsidy_chunk);
 
	if (s->cargo_type == CT_INVALID) delete s;
 
	return ret;
 
}
 

	
 
static const OldChunks game_difficulty_chunk[] = {
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, max_no_competitors ),
 
	OCL_NULL( 2), // competitor_start_time
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_towns ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_industries ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, industry_density ),
 
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, initial_interest ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_costs ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, competitor_speed ),
 
	OCL_NULL( 2), // competitor_intelligence
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_breakdowns ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, subsidy_multiplier ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, construction_cost ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, terrain_type ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, quantity_sea_lakes ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, economy ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, line_reverse_mode ),
 
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, disasters ),
 
	OCL_END()
 
};
 

	
 
static bool LoadOldGameDifficulty(LoadgameState *ls, int num)
 
{
 
	bool ret = LoadChunk(ls, &_settings_game.difficulty, game_difficulty_chunk);
 
	_settings_game.difficulty.max_loan *= 1000;
 
	return ret;
 
}
 

	
 

	
 
static bool LoadOldMapPart1(LoadgameState *ls, int num)
 
{
 
	if (_savegame_type == SGT_TTO) {
 
		MemSetT(_m, 0, OLD_MAP_SIZE);
 
		MemSetT(_me, 0, OLD_MAP_SIZE);
 
	}
 

	
 
	for (uint i = 0; i < OLD_MAP_SIZE; i++) {
 
		_m[i].m1 = ReadByte(ls);
 
	}
 
	for (uint i = 0; i < OLD_MAP_SIZE; i++) {
 
		_m[i].m2 = ReadByte(ls);
 
	}
 

	
 
	if (_savegame_type != SGT_TTO) {
 
		for (uint i = 0; i < OLD_MAP_SIZE; i++) {
 
			_old_map3[i * 2] = ReadByte(ls);
 
			_old_map3[i * 2 + 1] = ReadByte(ls);
 
		}
 
		for (uint i = 0; i < OLD_MAP_SIZE / 4; i++) {
 
			byte b = ReadByte(ls);
 
			_m[i * 4 + 0].m6 = GB(b, 0, 2);
 
			_m[i * 4 + 1].m6 = GB(b, 2, 2);
 
			_m[i * 4 + 2].m6 = GB(b, 4, 2);
src/settings_type.h
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file settings_type.h Types related to global configuration settings. */
 

	
 
#ifndef SETTINGS_TYPE_H
 
#define SETTINGS_TYPE_H
 

	
 
#include "date_type.h"
 
#include "town_type.h"
 
#include "transport_type.h"
 
#include "network/core/config.h"
 
#include "company_type.h"
 
#include "openttd.h"
 

	
 
/** Available industry map generation densities. */
 
enum IndustryDensity {
 
	ID_FUND_ONLY, ///< The game does not build industries.
 
	ID_MINIMAL,   ///< Start with just the industries that must be present.
 
	ID_VERY_LOW,  ///< Very few industries at game start.
 
	ID_LOW,       ///< Few industries at game start.
 
	ID_NORMAL,    ///< Normal amount of industries at game start.
 
	ID_HIGH,      ///< Many industries at game start.
 

	
 
	ID_END,       ///< Number of industry density settings.
 
};
 

	
 
/** Settings related to the difficulty of the game */
 
struct DifficultySettings {
 
	byte   max_no_competitors;               ///< the number of competitors (AIs)
 
	byte   number_towns;                     ///< the amount of towns
 
	byte   number_industries;                ///< The industry density. @see IndustryDensity
 
	byte   industry_density;                 ///< The industry density. @see IndustryDensity
 
	uint32 max_loan;                         ///< the maximum initial loan
 
	byte   initial_interest;                 ///< amount of interest (to pay over the loan)
 
	byte   vehicle_costs;                    ///< amount of money spent on vehicle running cost
 
	byte   competitor_speed;                 ///< the speed at which the AI builds
 
	byte   vehicle_breakdowns;               ///< likelihood of vehicles breaking down
 
	byte   subsidy_multiplier;               ///< amount of subsidy
 
	byte   construction_cost;                ///< how expensive is building
 
	byte   terrain_type;                     ///< the mountainousness of the landscape
 
	byte   quantity_sea_lakes;               ///< the amount of seas/lakes
 
	byte   economy;                          ///< how volatile is the economy
 
	byte   line_reverse_mode;                ///< reversing at stations or not
 
	byte   disasters;                        ///< are disasters enabled
 
	byte   town_council_tolerance;           ///< minimum required town ratings to be allowed to demolish stuff
 
	byte   diff_level;                       ///< the difficulty level
 
};
 

	
 
/** Settings related to the GUI and other stuff that is not saved in the savegame. */
 
struct GUISettings {
 
	bool   sg_full_load_any;                 ///< new full load calculation, any cargo must be full read from pre v93 savegames
 
	bool   lost_vehicle_warn;                ///< if a vehicle can't find its destination, show a warning
 
	uint8  order_review_system;              ///< perform order reviews on vehicles
 
	bool   vehicle_income_warn;              ///< if a vehicle isn't generating income, show a warning
 
	bool   show_finances;                    ///< show finances at end of year
 
	bool   sg_new_nonstop;                   ///< ttdpatch compatible nonstop handling read from pre v93 savegames
 
	bool   new_nonstop;                      ///< ttdpatch compatible nonstop handling
 
	uint8  stop_location;                    ///< what is the default stop location of trains?
 
	bool   autoscroll;                       ///< scroll when moving mouse to the edge
 
	byte   errmsg_duration;                  ///< duration of error message
 
	byte   hover_delay;                      ///< time required to activate a hover event, in seconds
 
	bool   link_terraform_toolbar;           ///< display terraform toolbar when displaying rail, road, water and airport toolbars
 
	uint8  smallmap_land_colour;             ///< colour used for land and heightmap at the smallmap
 
	bool   reverse_scroll;                   ///< right-Click-Scrolling scrolls in the opposite direction
 
	bool   smooth_scroll;                    ///< smooth scroll viewports
 
	bool   measure_tooltip;                  ///< show a permanent tooltip when dragging tools
 
	byte   liveries;                         ///< options for displaying company liveries, 0=none, 1=self, 2=all
 
	bool   prefer_teamchat;                  ///< choose the chat message target with <ENTER>, true=all clients, false=your team
 
	uint8  advanced_vehicle_list;            ///< use the "advanced" vehicle list
 
	uint8  loading_indicators;               ///< show loading indicators
 
	uint8  default_rail_type;                ///< the default rail type for the rail GUI
 
	uint8  toolbar_pos;                      ///< position of toolbars, 0=left, 1=center, 2=right
 
	uint8  statusbar_pos;                    ///< position of statusbar, 0=left, 1=center, 2=right
 
	uint8  window_snap_radius;               ///< windows snap at each other if closer than this
 
	uint8  window_soft_limit;                ///< soft limit of maximum number of non-stickied non-vital windows (0 = no limit)
 
	bool   disable_unsuitable_building;      ///< disable infrastructure building when no suitable vehicles are available
 
	byte   autosave;                         ///< how often should we do autosaves?
 
	bool   threaded_saves;                   ///< should we do threaded saves?
 
	bool   keep_all_autosave;                ///< name the autosave in a different way
 
	bool   autosave_on_exit;                 ///< save an autosave when you quit the game, but do not ask "Do you really want to quit?"
src/table/settings.h
Show inline comments
 
@@ -303,97 +303,97 @@ static const char *_autosave_interval = 
 
static const char *_roadsides = "left|right";
 
static const char *_savegame_date = "long|short|iso";
 
#ifdef ENABLE_NETWORK
 
static const char *_server_langs = "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN";
 
#endif /* ENABLE_NETWORK */
 

	
 
static const SettingDesc _gameopt_settings[] = {
 
	/* In version 4 a new difficulty setting has been added to the difficulty settings,
 
	 * town attitude towards demolishing. Needs special handling because some dimwit thought
 
	 * it funny to have the GameDifficulty struct be an array while it is a struct of
 
	 * same-sized members
 
	 * XXX - To save file-space and since values are never bigger than about 10? only
 
	 * save the first 16 bits in the savegame. Question is why the values are still int32
 
	 * and why not byte for example?
 
	 * 'SLE_FILE_I16 | SLE_VAR_U16' in "diff_custom" is needed to get around SlArray() hack
 
	 * for savegames version 0 - though it is an array, it has to go through the byteswap process */
 
	 SDTG_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_FILE_I16 | SLE_VAR_U16,    C, 0, _old_diff_custom, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, 0,  3),
 
	 SDTG_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16,                    C, 0, _old_diff_custom, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, 4, SL_MAX_VERSION),
 

	
 
	      SDT_VAR(GameSettings, difficulty.diff_level,    SLE_UINT8,                     0, 0, 3, 0,  3, 0, STR_NULL, NULL),
 
	    SDT_OMANY(GameSettings, locale.currency,          SLE_UINT8,                     N, 0, 0, CUSTOM_CURRENCY_ID, _locale_currencies, STR_NULL, NULL, NULL),
 
	    SDT_OMANY(GameSettings, locale.units,             SLE_UINT8,                     N, 0, 1, 2, _locale_units, STR_NULL, NULL, NULL),
 
	/* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */
 
	    SDT_OMANY(GameSettings, game_creation.town_name,  SLE_UINT8,                     0, 0, 0, 255, _town_names, STR_NULL, NULL, NULL),
 
	    SDT_OMANY(GameSettings, game_creation.landscape,  SLE_UINT8,                     0, 0, 0, 3, _climates, STR_NULL, NULL, ConvertLandscape),
 
	      SDT_VAR(GameSettings, game_creation.snow_line,  SLE_UINT8,                     0, 0, DEF_SNOWLINE_HEIGHT * TILE_HEIGHT, MIN_SNOWLINE_HEIGHT * TILE_HEIGHT, MAX_SNOWLINE_HEIGHT * TILE_HEIGHT, 0, STR_NULL, NULL),
 
	 SDT_CONDNULL(                                                1,  0, 22),
 
 SDTC_CONDOMANY(              gui.autosave,             SLE_UINT8, 23, SL_MAX_VERSION, S, 0, 1, 4, _autosave_interval, STR_NULL, NULL),
 
	    SDT_OMANY(GameSettings, vehicle.road_side,        SLE_UINT8,                     0, 0, 1, 1, _roadsides, STR_NULL, NULL, NULL),
 
	    SDT_END()
 
};
 

	
 
/* Some settings do not need to be synchronised when playing in multiplayer.
 
 * These include for example the GUI settings and will not be saved with the
 
 * savegame.
 
 * It is also a bit tricky since you would think that service_interval
 
 * for example doesn't need to be synched. Every client assigns the
 
 * service_interval value to the v->service_interval, meaning that every client
 
 * assigns his value. If the setting was company-based, that would mean that
 
 * vehicles could decide on different moments that they are heading back to a
 
 * service depot, causing desyncs on a massive scale. */
 
const SettingDesc _settings[] = {
 
	/***************************************************************************/
 
	/* Saved settings variables. */
 
	/* Do not ADD or REMOVE something in this "difficulty.XXX" table or before it. It breaks savegame compatability. */
 
	 SDT_CONDVAR(GameSettings, difficulty.max_no_competitors,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,0,MAX_COMPANIES-1,1,STR_NULL,                                  MaxNoAIsChange),
 
	SDT_CONDNULL(                                                            1, 97, 109),
 
	 SDT_CONDVAR(GameSettings, difficulty.number_towns,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     2,     0,      4,  1, STR_NUM_VERY_LOW,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.number_industries,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, ID_END-1,  0,ID_END-1, 1, STR_FUNDING_ONLY,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.industry_density,          SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, ID_END-1,  0,ID_END-1, 1, STR_FUNDING_ONLY,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.max_loan,                 SLE_UINT32, 97, SL_MAX_VERSION, 0,NS|CR,300000,100000,500000,50000,STR_NULL,                               DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.initial_interest,          SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     2,     2,      4,  1, STR_NULL,                                  DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.vehicle_costs,             SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.competitor_speed,          SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,     0,      4,  1, STR_AI_SPEED_VERY_SLOW,                    DifficultyChange),
 
	SDT_CONDNULL(                                                            1, 97, 109),
 
	 SDT_CONDVAR(GameSettings, difficulty.vehicle_breakdowns,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     1,     0,      2,  1, STR_DISASTER_NONE,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.subsidy_multiplier,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,     0,      3,  1, STR_SUBSIDY_X1_5,                          DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.construction_cost,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.terrain_type,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     1,     0,      3,  1, STR_TERRAIN_TYPE_VERY_FLAT,                DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.quantity_sea_lakes,        SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      4,  1, STR_SEA_LEVEL_VERY_LOW,                    DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.economy,                   SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_ECONOMY_STEADY,                        DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.line_reverse_mode,         SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_REVERSE_AT_END_OF_LINE_AND_AT_STATIONS,DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.disasters,                 SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      1,  1, STR_DISASTERS_OFF,                         DifficultyChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.town_council_tolerance,    SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     0,     0,      2,  1, STR_CITY_APPROVAL_PERMISSIVE,              DifficultyNoiseChange),
 
	 SDT_CONDVAR(GameSettings, difficulty.diff_level,                SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     3,     0,      3,  0, STR_NULL,                                  DifficultyReset),
 

	
 
	/* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */
 
 SDT_CONDOMANY(GameSettings, game_creation.town_name,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0, 255, _town_names,      STR_NULL,                                  NULL, NULL),
 
 SDT_CONDOMANY(GameSettings, game_creation.landscape,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0,   3, _climates,        STR_NULL,                                  NULL, ConvertLandscape),
 
	 SDT_CONDVAR(GameSettings, game_creation.snow_line,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, DEF_SNOWLINE_HEIGHT * TILE_HEIGHT, MIN_SNOWLINE_HEIGHT * TILE_HEIGHT, MAX_SNOWLINE_HEIGHT * TILE_HEIGHT, 0, STR_NULL,     NULL),
 
 SDT_CONDOMANY(GameSettings, vehicle.road_side,                    SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 1,   1, _roadsides,       STR_NULL,                                  CheckRoadSide, NULL),
 

	
 
	    SDT_BOOL(GameSettings, construction.build_on_slopes,                                        0,NN,  true,                    STR_CONFIG_SETTING_BUILDONSLOPES,          NULL),
 
	 SDT_CONDVAR(GameSettings, construction.command_pause_level,     SLE_UINT8,154, SL_MAX_VERSION, 0,MS|NN,  1,    0,        3, 1, STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL,    NULL),
 
	 SDT_CONDVAR(GameSettings, construction.terraform_per_64k_frames,SLE_UINT32,156,SL_MAX_VERSION, 0, 0, 64 << 16, 0,  1 << 30, 1, STR_NULL, NULL),
 
	 SDT_CONDVAR(GameSettings, construction.terraform_frame_burst,  SLE_UINT16,156, SL_MAX_VERSION, 0, 0, 4096,     0,  1 << 30, 1, STR_NULL, NULL),
 
	 SDT_CONDVAR(GameSettings, construction.clear_per_64k_frames,   SLE_UINT32,156, SL_MAX_VERSION, 0, 0, 64 << 16, 0,  1 << 30, 1, STR_NULL, NULL),
 
	 SDT_CONDVAR(GameSettings, construction.clear_frame_burst,      SLE_UINT16,156, SL_MAX_VERSION, 0, 0, 4096,     0,  1 << 30, 1, STR_NULL, NULL),
 
	SDT_CONDBOOL(GameSettings, construction.autoslope,                          75, SL_MAX_VERSION, 0, 0,  true,                    STR_CONFIG_SETTING_AUTOSLOPE,              NULL),
 
	    SDT_BOOL(GameSettings, construction.extra_dynamite,                                         0, 0,  true,                    STR_CONFIG_SETTING_EXTRADYNAMITE,          NULL),
 
	 SDT_CONDVAR(GameSettings, construction.max_bridge_length,      SLE_UINT16,159, SL_MAX_VERSION, 0,NN,    64,    1,     2048, 1, STR_CONFIG_SETTING_MAX_BRIDGE_LENGTH,      NULL),
 
	 SDT_CONDVAR(GameSettings, construction.max_tunnel_length,      SLE_UINT16,159, SL_MAX_VERSION, 0,NN,    64,    1,     2048, 1, STR_CONFIG_SETTING_MAX_TUNNEL_LENGTH,      NULL),
 
	SDT_CONDNULL(                                                            1,  0, 158), // construction.longbridges
 
	    SDT_BOOL(GameSettings, construction.signal_side,                                            N,NN,  true,                    STR_CONFIG_SETTING_SIGNALSIDE,             RedrawScreen),
 
	    SDT_BOOL(GameSettings, station.never_expire_airports,                                       0,NN, false,                    STR_CONFIG_SETTING_NEVER_EXPIRE_AIRPORTS,  NULL),
 
	 SDT_CONDVAR(GameSettings, economy.town_layout,                  SLE_UINT8, 59, SL_MAX_VERSION, 0,MS,TL_ORIGINAL,TL_BEGIN,NUM_TLS - 1, 1, STR_CONFIG_SETTING_TOWN_LAYOUT,  TownFoundingChanged),
 
	SDT_CONDBOOL(GameSettings, economy.allow_town_roads,                       113, SL_MAX_VERSION, 0,NN,  true,                    STR_CONFIG_SETTING_ALLOW_TOWN_ROADS,       NULL),
 
	 SDT_CONDVAR(GameSettings, economy.found_town,                   SLE_UINT8,128, SL_MAX_VERSION, 0,MS,TF_FORBIDDEN,TF_BEGIN,TF_END - 1, 1, STR_CONFIG_SETTING_TOWN_FOUNDING, TownFoundingChanged),
 
	SDT_CONDBOOL(GameSettings, economy.allow_town_level_crossings,             143, SL_MAX_VERSION, 0,NN,  true,                    STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS, NULL),
 

	
 
	     SDT_VAR(GameSettings, vehicle.train_acceleration_model,     SLE_UINT8,                     0,MS,     0,     0,       1, 1, STR_CONFIG_SETTING_TRAIN_ACCELERATION_MODEL, TrainAccelerationModelChanged),
 
	 SDT_CONDVAR(GameSettings, vehicle.roadveh_acceleration_model,   SLE_UINT8,139, SL_MAX_VERSION, 0,MS,     0,     0,       1, 1, STR_CONFIG_SETTING_ROAD_VEHICLE_ACCELERATION_MODEL, RoadVehAccelerationModelChanged),
 
	 SDT_CONDVAR(GameSettings, vehicle.train_slope_steepness,        SLE_UINT8,133, SL_MAX_VERSION, 0, 0,     3,     0,      10, 1, STR_CONFIG_SETTING_TRAIN_SLOPE_STEEPNESS,  TrainSlopeSteepnessChanged),
 
	 SDT_CONDVAR(GameSettings, vehicle.roadveh_slope_steepness,      SLE_UINT8,139, SL_MAX_VERSION, 0, 0,     7,     0,      10, 1, STR_CONFIG_SETTING_ROAD_VEHICLE_SLOPE_STEEPNESS,  RoadVehSlopeSteepnessChanged),
 
	    SDT_BOOL(GameSettings, pf.forbid_90_deg,                                                    0, 0, false,                    STR_CONFIG_SETTING_FORBID_90_DEG,          NULL),
 
	 SDT_CONDVAR(GameSettings, vehicle.max_train_length,             SLE_UINT8,159, SL_MAX_VERSION, 0,NN,     7,     1,      64, 1, STR_CONFIG_SETTING_TRAIN_LENGTH,           NULL),
 
	SDT_CONDNULL(                                                          1,  0,   158), // vehicle.mammoth_trains
 
	 SDT_CONDVAR(GameSettings, vehicle.smoke_amount,                 SLE_UINT8,145, SL_MAX_VERSION, 0,MS,     1,     0,       2, 0, STR_CONFIG_SETTING_SMOKE_AMOUNT,           NULL),
0 comments (0 inline, 0 general)