Changeset - r26829:f1ebd010c392
[Not reviewed]
src/3rdparty/squirrel/squirrel/sqobject.cpp
Show inline comments
 
@@ -437,29 +437,29 @@ bool SQFunctionProto::Load(SQVM *v,SQUse
 
		f->_literals[i] = o;
 
	}
 
	_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
 

	
 
	for(i = 0; i < nparameters; i++){
 
		_CHECK_IO(ReadObject(v, up, read, o));
 
		f->_parameters[i] = o;
 
	}
 
	_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
 

	
 
	for(i = 0; i < noutervalues; i++){
 
		SQUnsignedInteger type;
 
		SQObjectPtr name;
 
		SQObjectPtr value_name;
 
		_CHECK_IO(SafeRead(v,read,up, &type, sizeof(SQUnsignedInteger)));
 
		_CHECK_IO(ReadObject(v, up, read, o));
 
		_CHECK_IO(ReadObject(v, up, read, name));
 
		f->_outervalues[i] = SQOuterVar(name,o, (SQOuterType)type);
 
		_CHECK_IO(ReadObject(v, up, read, value_name));
 
		f->_outervalues[i] = SQOuterVar(value_name,o, (SQOuterType)type);
 
	}
 
	_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
 

	
 
	for(i = 0; i < nlocalvarinfos; i++){
 
		SQLocalVarInfo lvi;
 
		_CHECK_IO(ReadObject(v, up, read, lvi._name));
 
		_CHECK_IO(SafeRead(v,read,up, &lvi._pos, sizeof(SQUnsignedInteger)));
 
		_CHECK_IO(SafeRead(v,read,up, &lvi._start_op, sizeof(SQUnsignedInteger)));
 
		_CHECK_IO(SafeRead(v,read,up, &lvi._end_op, sizeof(SQUnsignedInteger)));
 
		f->_localvarinfos[i] = lvi;
 
	}
 
	_CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -772,25 +772,24 @@ CommandCost CmdAutoreplaceVehicle(DoComm
 
		 * Vehicle construction needs random bits, so we have to save the random seeds
 
		 * to prevent desyncs and to replay newgrf callbacks during DC_EXEC */
 
		SavedRandomSeeds saved_seeds;
 
		SaveRandomSeeds(&saved_seeds);
 
		if (free_wagon) {
 
			cost.AddCost(ReplaceFreeUnit(&v, flags & ~DC_EXEC, &nothing_to_do));
 
		} else {
 
			cost.AddCost(ReplaceChain(&v, flags & ~DC_EXEC, wagon_removal, &nothing_to_do));
 
		}
 
		RestoreRandomSeeds(saved_seeds);
 

	
 
		if (cost.Succeeded() && (flags & DC_EXEC) != 0) {
 
			CommandCost ret;
 
			if (free_wagon) {
 
				ret = ReplaceFreeUnit(&v, flags, &nothing_to_do);
 
			} else {
 
				ret = ReplaceChain(&v, flags, wagon_removal, &nothing_to_do);
 
			}
 
			assert(ret.Succeeded() && ret.GetCost() == cost.GetCost());
 
		}
 

	
 
		/* Restart the vehicle */
 
		if (!was_stopped) cost.AddCost(DoCmdStartStopVehicle(v, false));
 
	}
 

	
src/base_media_func.h
Show inline comments
 
@@ -39,25 +39,25 @@ template <class T, size_t Tnum_files, bo
 
bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
 
{
 
	IniGroup *metadata = ini->GetGroup("metadata");
 
	IniItem *item;
 

	
 
	fetch_metadata("name");
 
	this->name = *item->value;
 

	
 
	fetch_metadata("description");
 
	this->description[std::string{}] = *item->value;
 

	
 
	/* Add the translations of the descriptions too. */
 
	for (const IniItem *item = metadata->item; item != nullptr; item = item->next) {
 
	for (item = metadata->item; item != nullptr; item = item->next) {
 
		if (item->name.compare(0, 12, "description.") != 0) continue;
 

	
 
		this->description[item->name.substr(12)] = item->value.value_or("");
 
	}
 

	
 
	fetch_metadata("shortname");
 
	for (uint i = 0; (*item->value)[i] != '\0' && i < 4; i++) {
 
		this->shortname |= ((uint8)(*item->value)[i]) << (i * 8);
 
	}
 

	
 
	fetch_metadata("version");
 
	this->version = atoi(item->value->c_str());
src/company_gui.cpp
Show inline comments
 
@@ -624,37 +624,36 @@ private:
 
	uint32 sel;
 
	LiveryClass livery_class;
 
	Dimension square;
 
	uint rows;
 
	uint line_height;
 
	GUIGroupList groups;
 
	std::vector<int> indents;
 
	Scrollbar *vscroll;
 

	
 
	void ShowColourDropDownMenu(uint32 widget)
 
	{
 
		uint32 used_colours = 0;
 
		const Company *c;
 
		const Livery *livery, *default_livery = nullptr;
 
		bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
 
		byte default_col = 0;
 

	
 
		/* Disallow other company colours for the primary colour */
 
		if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) {
 
			for (const Company *c : Company::Iterate()) {
 
				if (c->index != _local_company) SetBit(used_colours, c->colour);
 
			}
 
		}
 

	
 
		c = Company::Get((CompanyID)this->window_number);
 
		const Company *c = Company::Get((CompanyID)this->window_number);
 

	
 
		if (this->livery_class < LC_GROUP_RAIL) {
 
			/* Get the first selected livery to use as the default dropdown item */
 
			LiveryScheme scheme;
 
			for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
 
				if (HasBit(this->sel, scheme)) break;
 
			}
 
			if (scheme == LS_END) scheme = LS_DEFAULT;
 
			livery = &c->livery[scheme];
 
			if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
 
		} else {
 
			const Group *g = Group::Get(this->sel);
src/gfx.cpp
Show inline comments
 
@@ -1318,49 +1318,48 @@ void DoPaletteAnimations()
 
{
 
	std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
 

	
 
	/* Animation counter for the palette animation. */
 
	static int palette_animation_counter = 0;
 
	palette_animation_counter += 8;
 

	
 
	Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 
	const Colour *s;
 
	const ExtraPaletteValues *ev = &_extra_palette_values;
 
	Colour old_val[PALETTE_ANIM_SIZE];
 
	const uint old_tc = palette_animation_counter;
 
	uint i;
 
	uint j;
 

	
 
	if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
 
		palette_animation_counter = 0;
 
	}
 

	
 
	Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START];  // Points to where animations are taking place on the palette
 
	/* Makes a copy of the current animation palette in old_val,
 
	 * so the work on the current palette could be compared, see if there has been any changes */
 
	memcpy(old_val, palette_pos, sizeof(old_val));
 

	
 
	/* Fizzy Drink bubbles animation */
 
	s = ev->fizzy_drink;
 
	j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK);
 
	for (i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
 
	for (uint i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
 
		*palette_pos++ = s[j];
 
		j++;
 
		if (j == EPV_CYCLES_FIZZY_DRINK) j = 0;
 
	}
 

	
 
	/* Oil refinery fire animation */
 
	s = ev->oil_refinery;
 
	j = EXTR2(512, EPV_CYCLES_OIL_REFINERY);
 
	for (i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
 
	for (uint i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
 
		*palette_pos++ = s[j];
 
		j++;
 
		if (j == EPV_CYCLES_OIL_REFINERY) j = 0;
 
	}
 

	
 
	/* Radio tower blinking */
 
	{
 
		byte i = (palette_animation_counter >> 1) & 0x7F;
 
		byte v;
 

	
 
		if (i < 0x3f) {
 
			v = 255;
 
@@ -1382,43 +1381,43 @@ void DoPaletteAnimations()
 
		} else {
 
			v = 20;
 
		}
 
		palette_pos->r = v;
 
		palette_pos->g = 0;
 
		palette_pos->b = 0;
 
		palette_pos++;
 
	}
 

	
 
	/* Handle lighthouse and stadium animation */
 
	s = ev->lighthouse;
 
	j = EXTR(256, EPV_CYCLES_LIGHTHOUSE);
 
	for (i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) {
 
	for (uint i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) {
 
		*palette_pos++ = s[j];
 
		j++;
 
		if (j == EPV_CYCLES_LIGHTHOUSE) j = 0;
 
	}
 

	
 
	/* Dark blue water */
 
	s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_toyland : ev->dark_water;
 
	j = EXTR(320, EPV_CYCLES_DARK_WATER);
 
	for (i = 0; i != EPV_CYCLES_DARK_WATER; i++) {
 
	for (uint i = 0; i != EPV_CYCLES_DARK_WATER; i++) {
 
		*palette_pos++ = s[j];
 
		j++;
 
		if (j == EPV_CYCLES_DARK_WATER) j = 0;
 
	}
 

	
 
	/* Glittery water */
 
	s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->glitter_water_toyland : ev->glitter_water;
 
	j = EXTR(128, EPV_CYCLES_GLITTER_WATER);
 
	for (i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) {
 
	for (uint i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) {
 
		*palette_pos++ = s[j];
 
		j += 3;
 
		if (j >= EPV_CYCLES_GLITTER_WATER) j -= EPV_CYCLES_GLITTER_WATER;
 
	}
 

	
 
	if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
 
		palette_animation_counter = old_tc;
 
	} else {
 
		if (memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0 && _cur_palette.count_dirty == 0) {
 
			/* Did we changed anything on the palette? Seems so.  Mark it as dirty */
 
			_cur_palette.first_dirty = PALETTE_ANIM_START;
 
			_cur_palette.count_dirty = PALETTE_ANIM_SIZE;
 
@@ -1660,41 +1659,41 @@ void DrawDirtyBlocks()
 
					*p = 0;
 
					p += _dirty_bytes_per_line;
 
					bottom += DIRTY_BLOCK_HEIGHT;
 
				} while (bottom != h && *p != 0);
 

	
 
				/* Try coalescing to the right too. */
 
				h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
 
				assert(h2 > 0);
 
				p = b;
 

	
 
				while (right != w) {
 
					byte *p2 = ++p;
 
					int h = h2;
 
					int i = h2;
 
					/* Check if a full line of dirty flags is set. */
 
					do {
 
						if (!*p2) goto no_more_coalesc;
 
						p2 += _dirty_bytes_per_line;
 
					} while (--h != 0);
 
					} while (--i != 0);
 

	
 
					/* Wohoo, can combine it one step to the right!
 
					 * Do that, and clear the bits. */
 
					right += DIRTY_BLOCK_WIDTH;
 

	
 
					h = h2;
 
					i = h2;
 
					p2 = p;
 
					do {
 
						*p2 = 0;
 
						p2 += _dirty_bytes_per_line;
 
					} while (--h != 0);
 
					} while (--i != 0);
 
				}
 
				no_more_coalesc:
 

	
 
				left = x;
 
				top = y;
 

	
 
				if (left   < _invalid_rect.left  ) left   = _invalid_rect.left;
 
				if (top    < _invalid_rect.top   ) top    = _invalid_rect.top;
 
				if (right  > _invalid_rect.right ) right  = _invalid_rect.right;
 
				if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
 

	
 
				if (left < right && top < bottom) {
src/industry_cmd.cpp
Show inline comments
 
@@ -653,39 +653,35 @@ static void AnimateTile_Industry(TileInd
 
			}
 

	
 
			SetAnimationFrame(tile, m);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		break;
 

	
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
 
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
 
		if ((_tick_counter & 3) == 0) {
 
			IndustryGfx gfx = GetIndustryGfx(tile);
 

	
 
			gfx = (gfx < 155) ? gfx + 1 : 148;
 
			SetIndustryGfx(tile, gfx);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		break;
 

	
 
	case GFX_OILWELL_ANIMATED_1:
 
	case GFX_OILWELL_ANIMATED_2:
 
	case GFX_OILWELL_ANIMATED_3:
 
		if ((_tick_counter & 7) == 0) {
 
			bool b = Chance16(1, 7);
 
			IndustryGfx gfx = GetIndustryGfx(tile);
 

	
 
			byte m = GetAnimationFrame(tile) + 1;
 
			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
 
				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
 
				SetIndustryConstructionStage(tile, 3);
 
				DeleteAnimatedTile(tile);
 
			} else {
 
				SetAnimationFrame(tile, m);
 
				SetIndustryGfx(tile, gfx);
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
		break;
 
@@ -1458,31 +1454,31 @@ static CommandCost CheckIfIndustryTilesA
 

	
 
			/* Perform land/water check if not disabled */
 
			if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
			if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house
 
					((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
 
				if (!IsTileType(cur_tile, MP_HOUSE)) {
 
					return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
 
				}
 

	
 
				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 
				Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 
				CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, cur_tile);
 
				ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, cur_tile);
 
				cur_company.Restore();
 

	
 
				if (ret.Failed()) return ret;
 
			} else {
 
				/* Clear the tiles, but do not affect town ratings */
 
				CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
 
				ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
 
				if (ret.Failed()) return ret;
 
			}
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Check slope requirements for industry tiles.
 
 * @param tile                    Position to check.
 
 * @param layout                  Industry tiles table.
src/industry_gui.cpp
Show inline comments
 
@@ -2766,25 +2766,25 @@ struct IndustryCargoesWindow : public Wi
 
		row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
 

	
 
		const IndustrySpec *central_sp = GetIndustrySpec(displayed_it);
 
		bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
 
		bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
 
		/* Make a field consisting of two cargo columns. */
 
		int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)) + houses_supply;
 
		int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
 
		int num_indrows = std::max(3, std::max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
 
		for (int i = 0; i < num_indrows; i++) {
 
			CargoesRow &row = this->fields.emplace_back();
 
			row = this->fields.emplace_back();
 
			row.columns[0].MakeEmpty(CFT_EMPTY);
 
			row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
 
			row.columns[2].MakeEmpty(CFT_EMPTY);
 
			row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
 
			row.columns[4].MakeEmpty(CFT_EMPTY);
 
		}
 
		/* Add central industry. */
 
		int central_row = 1 + num_indrows / 2;
 
		this->fields[central_row].columns[2].MakeIndustry(displayed_it);
 
		this->fields[central_row].ConnectIndustryProduced(2);
 
		this->fields[central_row].ConnectIndustryAccepted(2);
 

	
 
@@ -2841,25 +2841,25 @@ struct IndustryCargoesWindow : public Wi
 
		row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
 
		row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
 
		row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[4].MakeEmpty(CFT_SMALL_EMPTY);
 

	
 
		bool houses_supply = HousesCanSupply(&cid, 1);
 
		bool houses_accept = HousesCanAccept(&cid, 1);
 
		int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
 
		int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
 
		int num_indrows = std::max(num_supp, num_cust);
 
		for (int i = 0; i < num_indrows; i++) {
 
			CargoesRow &row = this->fields.emplace_back();
 
			row = this->fields.emplace_back();
 
			row.columns[0].MakeEmpty(CFT_EMPTY);
 
			row.columns[1].MakeCargo(&cid, 1);
 
			row.columns[2].MakeEmpty(CFT_EMPTY);
 
			row.columns[3].MakeEmpty(CFT_EMPTY);
 
			row.columns[4].MakeEmpty(CFT_EMPTY);
 
		}
 

	
 
		this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
 

	
 
		/* Add suppliers and customers of the cargo. */
 
		int supp_count = 0;
 
		int cust_count = 0;
src/network/network_content.cpp
Show inline comments
 
@@ -1045,29 +1045,29 @@ void ClientNetworkContentSocketHandler::
 

	
 
			force_selection = true;
 
			break;
 
		}
 

	
 
		/* So something depended directly on us */
 
		if (force_selection) continue;
 

	
 
		/* Nothing depends on us, mark the whole graph as unselected.
 
		 * After that's done run over them once again to test their children
 
		 * to unselect. Don't do it immediately because it'll do exactly what
 
		 * we're doing now. */
 
		for (const ContentInfo *c : parents) {
 
			if (c->state == ContentInfo::AUTOSELECTED) this->Unselect(c->id);
 
		for (const ContentInfo *parent : parents) {
 
			if (parent->state == ContentInfo::AUTOSELECTED) this->Unselect(parent->id);
 
		}
 
		for (const ContentInfo *c : parents) {
 
			this->CheckDependencyState(this->GetContent(c->id));
 
		for (const ContentInfo *parent : parents) {
 
			this->CheckDependencyState(this->GetContent(parent->id));
 
		}
 
	}
 
}
 

	
 
/** Clear all downloaded content information. */
 
void ClientNetworkContentSocketHandler::Clear()
 
{
 
	for (ContentInfo *c : this->infos) delete c;
 

	
 
	this->infos.clear();
 
	this->requested.clear();
 
	this->reverse_dependency_map.clear();
src/newgrf.cpp
Show inline comments
 
@@ -4261,31 +4261,31 @@ static ChangeInfoResult RailTypeChangeIn
 

	
 
			case 0x0E: // Compatible railtype list
 
			case 0x0F: // Powered railtype list
 
			case 0x18: // Railtype list required for date introduction
 
			case 0x19: // Introduced railtype list
 
			{
 
				/* Rail type compatibility bits are added to the existing bits
 
				 * to allow multiple GRFs to modify compatibility with the
 
				 * default rail types. */
 
				int n = buf->ReadByte();
 
				for (int j = 0; j != n; j++) {
 
					RailTypeLabel label = buf->ReadDWord();
 
					RailType rt = GetRailTypeByLabel(BSWAP32(label), false);
 
					if (rt != INVALID_RAILTYPE) {
 
					RailType resolved_rt = GetRailTypeByLabel(BSWAP32(label), false);
 
					if (resolved_rt != INVALID_RAILTYPE) {
 
						switch (prop) {
 
							case 0x0F: SetBit(rti->powered_railtypes, rt);               FALLTHROUGH; // Powered implies compatible.
 
							case 0x0E: SetBit(rti->compatible_railtypes, rt);            break;
 
							case 0x18: SetBit(rti->introduction_required_railtypes, rt); break;
 
							case 0x19: SetBit(rti->introduces_railtypes, rt);            break;
 
							case 0x0F: SetBit(rti->powered_railtypes, resolved_rt);               FALLTHROUGH; // Powered implies compatible.
 
							case 0x0E: SetBit(rti->compatible_railtypes, resolved_rt);            break;
 
							case 0x18: SetBit(rti->introduction_required_railtypes, resolved_rt); break;
 
							case 0x19: SetBit(rti->introduces_railtypes, resolved_rt);            break;
 
						}
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case 0x10: // Rail Type flags
 
				rti->flags = (RailTypeFlags)buf->ReadByte();
 
				break;
 

	
 
			case 0x11: // Curve speed advantage
 
				rti->curve_speed = buf->ReadByte();
 
@@ -4475,30 +4475,30 @@ static ChangeInfoResult RoadTypeChangeIn
 
				AddStringForMapping(buf->ReadWord(), &rti->strings.new_engine);
 
				break;
 

	
 
			case 0x0F: // Powered roadtype list
 
			case 0x18: // Roadtype list required for date introduction
 
			case 0x19: { // Introduced roadtype list
 
				/* Road type compatibility bits are added to the existing bits
 
				 * to allow multiple GRFs to modify compatibility with the
 
				 * default road types. */
 
				int n = buf->ReadByte();
 
				for (int j = 0; j != n; j++) {
 
					RoadTypeLabel label = buf->ReadDWord();
 
					RoadType rt = GetRoadTypeByLabel(BSWAP32(label), false);
 
					if (rt != INVALID_ROADTYPE) {
 
					RoadType resolved_rt = GetRoadTypeByLabel(BSWAP32(label), false);
 
					if (resolved_rt != INVALID_ROADTYPE) {
 
						switch (prop) {
 
							case 0x0F: SetBit(rti->powered_roadtypes, rt);               break;
 
							case 0x18: SetBit(rti->introduction_required_roadtypes, rt); break;
 
							case 0x19: SetBit(rti->introduces_roadtypes, rt);            break;
 
							case 0x0F: SetBit(rti->powered_roadtypes, resolved_rt);               break;
 
							case 0x18: SetBit(rti->introduction_required_roadtypes, resolved_rt); break;
 
							case 0x19: SetBit(rti->introduces_roadtypes, resolved_rt);            break;
 
						}
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case 0x10: // Road Type flags
 
				rti->flags = (RoadTypeFlags)buf->ReadByte();
 
				break;
 

	
 
			case 0x13: // Construction cost factor
 
				rti->cost_multiplier = buf->ReadWord();
src/newgrf_gui.cpp
Show inline comments
 
@@ -1276,34 +1276,34 @@ struct NewGRFWindow : public Window, New
 
		);
 
		this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || HasBit(this->avail_sel->flags, GCF_INVALID));
 
		this->SetWidgetDisabledState(WID_NS_UPGRADE, !this->editable || this->actives == nullptr || !this->CanUpgradeCurrent());
 

	
 
		bool disable_all = this->active_sel == nullptr || !this->editable;
 
		this->SetWidgetsDisabledState(disable_all,
 
			WID_NS_REMOVE,
 
			WID_NS_MOVE_UP,
 
			WID_NS_MOVE_DOWN,
 
			WIDGET_LIST_END
 
		);
 

	
 
		const GRFConfig *c = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel;
 
		const GRFConfig *selected_config = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel;
 
		for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
 
			this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, c == nullptr || c->GetTextfile(tft) == nullptr);
 
			this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, selected_config == nullptr || selected_config->GetTextfile(tft) == nullptr);
 
		}
 
		this->SetWidgetDisabledState(WID_NS_OPEN_URL, c == nullptr || StrEmpty(c->GetURL()));
 
		this->SetWidgetDisabledState(WID_NS_OPEN_URL, selected_config == nullptr || StrEmpty(selected_config->GetURL()));
 

	
 
		this->SetWidgetDisabledState(WID_NS_SET_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
 
		this->SetWidgetDisabledState(WID_NS_VIEW_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
 
		this->SetWidgetDisabledState(WID_NS_TOGGLE_PALETTE, disable_all ||
 
				(!(_settings_client.gui.newgrf_developer_tools || _settings_client.gui.scenario_developer) && ((c->palette & GRFP_GRF_MASK) != GRFP_GRF_UNSET)));
 
				(!(_settings_client.gui.newgrf_developer_tools || _settings_client.gui.scenario_developer) && ((selected_config->palette & GRFP_GRF_MASK) != GRFP_GRF_UNSET)));
 

	
 
		if (!disable_all) {
 
			/* All widgets are now enabled, so disable widgets we can't use */
 
			if (this->active_sel == this->actives)    this->DisableWidget(WID_NS_MOVE_UP);
 
			if (this->active_sel->next == nullptr)       this->DisableWidget(WID_NS_MOVE_DOWN);
 
		}
 

	
 
		this->SetWidgetDisabledState(WID_NS_PRESET_DELETE, this->preset == -1);
 

	
 
		bool has_missing = false;
 
		bool has_compatible = false;
 
		for (const GRFConfig *c = this->actives; !has_missing && c != nullptr; c = c->next) {
src/openttd.cpp
Show inline comments
 
@@ -1394,25 +1394,25 @@ void StateGameLoop()
 
		Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
		BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
 
		AnimateAnimatedTiles();
 
		IncreaseDate();
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
 

	
 
#ifndef DEBUG_DUMP_COMMANDS
 
		{
 
			PerformanceMeasurer framerate(PFE_ALLSCRIPTS);
 
			PerformanceMeasurer script_framerate(PFE_ALLSCRIPTS);
 
			AI::GameLoop();
 
			Game::GameLoop();
 
		}
 
#endif
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowGameTickEvent();
 
		NewsLoop();
 
		cur_company.Restore();
 
	}
 

	
 
	assert(IsLocalCompany());
src/order_cmd.cpp
Show inline comments
 
@@ -745,25 +745,25 @@ CommandCost CmdInsertOrder(DoCommandFlag
 

	
 
	/* Validate properties we don't want to have different from default as they are set by other commands. */
 
	if (new_order.GetRefitCargo() != CT_NO_REFIT || new_order.GetWaitTime() != 0 || new_order.GetTravelTime() != 0 || new_order.GetMaxSpeed() != UINT16_MAX) return CMD_ERROR;
 

	
 
	/* Check if the inserted order is to the correct destination (owner, type),
 
	 * and has the correct flags if any */
 
	switch (new_order.GetType()) {
 
		case OT_GOTO_STATION: {
 
			const Station *st = Station::GetIfValid(new_order.GetDestination());
 
			if (st == nullptr) return CMD_ERROR;
 

	
 
			if (st->owner != OWNER_NONE) {
 
				CommandCost ret = CheckOwnership(st->owner);
 
				ret = CheckOwnership(st->owner);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
 
			for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
 
				if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
 
			}
 

	
 
			/* Non stop only allowed for ground vehicles. */
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
 

	
 
			/* Filter invalid load/unload types. */
 
@@ -791,36 +791,36 @@ CommandCost CmdInsertOrder(DoCommandFlag
 
			}
 

	
 
			break;
 
		}
 

	
 
		case OT_GOTO_DEPOT: {
 
			if ((new_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) == 0) {
 
				if (v->type == VEH_AIRCRAFT) {
 
					const Station *st = Station::GetIfValid(new_order.GetDestination());
 

	
 
					if (st == nullptr) return CMD_ERROR;
 

	
 
					CommandCost ret = CheckOwnership(st->owner);
 
					ret = CheckOwnership(st->owner);
 
					if (ret.Failed()) return ret;
 

	
 
					if (!CanVehicleUseStation(v, st) || !st->airport.HasHangar()) {
 
						return CMD_ERROR;
 
					}
 
				} else {
 
					const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
 

	
 
					if (dp == nullptr) return CMD_ERROR;
 

	
 
					CommandCost ret = CheckOwnership(GetTileOwner(dp->xy));
 
					ret = CheckOwnership(GetTileOwner(dp->xy));
 
					if (ret.Failed()) return ret;
 

	
 
					switch (v->type) {
 
						case VEH_TRAIN:
 
							if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
 
							break;
 

	
 
						case VEH_ROAD:
 
							if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
 
							break;
 

	
 
						case VEH_SHIP:
 
@@ -840,33 +840,33 @@ CommandCost CmdInsertOrder(DoCommandFlag
 
		}
 

	
 
		case OT_GOTO_WAYPOINT: {
 
			const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
 
			if (wp == nullptr) return CMD_ERROR;
 

	
 
			switch (v->type) {
 
				default: return CMD_ERROR;
 

	
 
				case VEH_TRAIN: {
 
					if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
 

	
 
					CommandCost ret = CheckOwnership(wp->owner);
 
					ret = CheckOwnership(wp->owner);
 
					if (ret.Failed()) return ret;
 
					break;
 
				}
 

	
 
				case VEH_SHIP:
 
					if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
 
					if (wp->owner != OWNER_NONE) {
 
						CommandCost ret = CheckOwnership(wp->owner);
 
						ret = CheckOwnership(wp->owner);
 
						if (ret.Failed()) return ret;
 
					}
 
					break;
 
			}
 

	
 
			/* Order flags can be any of the following for waypoints:
 
			 * [non-stop]
 
			 * non-stop orders (if any) are only valid for trains */
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
 
			break;
 
		}
 

	
 
@@ -1505,25 +1505,25 @@ CommandCost CmdCloneOrder(DoCommandFlag 
 
	if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(dst->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	switch (action) {
 
		case CO_SHARE: {
 
			Vehicle *src = Vehicle::GetIfValid(veh_src);
 

	
 
			/* Sanity checks */
 
			if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
 

	
 
			CommandCost ret = CheckOwnership(src->owner);
 
			ret = CheckOwnership(src->owner);
 
			if (ret.Failed()) return ret;
 

	
 
			/* Trucks can't share orders with busses (and visa versa) */
 
			if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
 
				return CMD_ERROR;
 
			}
 

	
 
			/* Is the vehicle already in the shared list? */
 
			if (src->FirstShared() == dst->FirstShared()) return CMD_ERROR;
 

	
 
			for (const Order *order : src->Orders()) {
 
				if (!OrderGoesToStation(dst, order)) continue;
 
@@ -1562,25 +1562,25 @@ CommandCost CmdCloneOrder(DoCommandFlag 
 

	
 
				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
			}
 
			break;
 
		}
 

	
 
		case CO_COPY: {
 
			Vehicle *src = Vehicle::GetIfValid(veh_src);
 

	
 
			/* Sanity checks */
 
			if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
 

	
 
			CommandCost ret = CheckOwnership(src->owner);
 
			ret = CheckOwnership(src->owner);
 
			if (ret.Failed()) return ret;
 

	
 
			/* Trucks can't copy all the orders from busses (and visa versa),
 
			 * and neither can helicopters and aircraft. */
 
			for (const Order *order : src->Orders()) {
 
				if (OrderGoesToStation(dst, order) &&
 
						!CanVehicleUseStation(dst, Station::Get(order->GetDestination()))) {
 
					return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
 
				}
 
			}
 

	
 
			/* Check for aircraft range limits. */
 
@@ -1762,30 +1762,27 @@ void CheckOrders(const Vehicle *v)
 
 * @param hangar Only used for airports in the destination.
 
 *               When false, remove airport and hangar orders.
 
 *               When true, remove either airport or hangar order.
 
 */
 
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
 
{
 
	/* Aircraft have StationIDs for depot orders and never use DepotIDs
 
	 * This fact is handled specially below
 
	 */
 

	
 
	/* Go through all vehicles */
 
	for (Vehicle *v : Vehicle::Iterate()) {
 
		Order *order;
 

	
 
		order = &v->current_order;
 
		if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : order->GetType()) == type &&
 
		if ((v->type == VEH_AIRCRAFT && v->current_order.IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : v->current_order.GetType()) == type &&
 
				(!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
 
			order->MakeDummy();
 
			v->current_order.MakeDummy();
 
			SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 
		}
 

	
 
		/* Clear the order from the order-list */
 
		int id = -1;
 
		for (Order *order : v->Orders()) {
 
			id++;
 
restart:
 

	
 
			OrderType ot = order->GetType();
 
			if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
 
			if (ot == OT_GOTO_DEPOT && hangar && v->type != VEH_AIRCRAFT) continue; // Not an aircraft? Can't have a hangar order.
src/rail_cmd.cpp
Show inline comments
 
@@ -522,25 +522,25 @@ CommandCost CmdBuildSingleRail(DoCommand
 
				if (roadtype_road != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_road)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
 
				if (roadtype_tram != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_tram)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
 

	
 
				RoadBits road = GetRoadBits(tile, RTT_ROAD);
 
				RoadBits tram = GetRoadBits(tile, RTT_TRAM);
 
				if ((track == TRACK_X && ((road | tram) & ROAD_X) == 0) ||
 
						(track == TRACK_Y && ((road | tram) & ROAD_Y) == 0)) {
 
					Owner road_owner = GetRoadOwner(tile, RTT_ROAD);
 
					Owner tram_owner = GetRoadOwner(tile, RTT_TRAM);
 
					/* Disallow breaking end-of-line of someone else
 
					 * so trams can still reverse on this tile. */
 
					if (Company::IsValidID(tram_owner) && HasExactlyOneBit(tram)) {
 
						CommandCost ret = CheckOwnership(tram_owner);
 
						ret = CheckOwnership(tram_owner);
 
						if (ret.Failed()) return ret;
 
					}
 

	
 
					uint num_new_road_pieces = (road != ROAD_NONE) ? 2 - CountBits(road) : 0;
 
					if (num_new_road_pieces > 0) {
 
						cost.AddCost(num_new_road_pieces * RoadBuildCost(roadtype_road));
 
					}
 

	
 
					uint num_new_tram_pieces = (tram != ROAD_NONE) ? 2 - CountBits(tram) : 0;
 
					if (num_new_tram_pieces > 0) {
 
						cost.AddCost(num_new_tram_pieces * RoadBuildCost(roadtype_tram));
 
					}
 
@@ -884,25 +884,25 @@ static CommandCost CmdRailTrackHelper(Do
 

	
 
	if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (end_tile >= Map::Size() || tile >= Map::Size()) return CMD_ERROR;
 

	
 
	Trackdir trackdir = TrackToTrackdir(track);
 

	
 
	CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
 
	if (ret.Failed()) return ret;
 

	
 
	bool had_success = false;
 
	CommandCost last_error = CMD_ERROR;
 
	for (;;) {
 
		CommandCost ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
 
		ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
 

	
 
		if (ret.Failed()) {
 
			last_error = ret;
 
			if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
 
				if (fail_on_obstacle) return last_error;
 
				break;
 
			}
 

	
 
			/* Ownership errors are more important. */
 
			if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break;
 
		} else {
 
			had_success = true;
 
@@ -1582,25 +1582,25 @@ CommandCost CmdConvertRail(DoCommandFlag
 
		CommandCost ret = CheckTileOwnership(tile);
 
		if (ret.Failed()) {
 
			error = ret;
 
			continue;
 
		}
 

	
 
		std::vector<Train *> vehicles_affected;
 

	
 
		/* Vehicle on the tile when not converting Rail <-> ElRail
 
		 * Tunnels and bridges have special check later */
 
		if (tt != MP_TUNNELBRIDGE) {
 
			if (!IsCompatibleRail(type, totype)) {
 
				CommandCost ret = IsPlainRailTile(tile) ? EnsureNoTrainOnTrackBits(tile, GetTrackBits(tile)) : EnsureNoVehicleOnGround(tile);
 
				ret = IsPlainRailTile(tile) ? EnsureNoTrainOnTrackBits(tile, GetTrackBits(tile)) : EnsureNoVehicleOnGround(tile);
 
				if (ret.Failed()) {
 
					error = ret;
 
					continue;
 
				}
 
			}
 
			if (flags & DC_EXEC) { // we can safely convert, too
 
				TrackBits reserved = GetReservedTrackbits(tile);
 
				Track     track;
 
				while ((track = RemoveFirstTrack(&reserved)) != INVALID_TRACK) {
 
					Train *v = GetTrainForReservation(tile, track);
 
					if (v != nullptr && !HasPowerOnRail(v->railtype, totype)) {
 
						/* No power on new rail type, reroute. */
 
@@ -1666,25 +1666,25 @@ CommandCost CmdConvertRail(DoCommandFlag
 
				/* If both ends of tunnel/bridge are in the range, do not try to convert twice -
 
				 * it would cause assert because of different test and exec runs */
 
				if (endtile < tile) {
 
					if (diagonal) {
 
						if (DiagonalTileArea(area_start, area_end).Contains(endtile)) continue;
 
					} else {
 
						if (OrthogonalTileArea(area_start, area_end).Contains(endtile)) continue;
 
					}
 
				}
 

	
 
				/* When not converting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
 
				if (!IsCompatibleRail(GetRailType(tile), totype)) {
 
					CommandCost ret = TunnelBridgeIsFree(tile, endtile);
 
					ret = TunnelBridgeIsFree(tile, endtile);
 
					if (ret.Failed()) {
 
						error = ret;
 
						continue;
 
					}
 
				}
 

	
 
				if (flags & DC_EXEC) {
 
					Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
 
					if (HasTunnelBridgeReservation(tile)) {
 
						Train *v = GetTrainForReservation(tile, track);
 
						if (v != nullptr && !HasPowerOnRail(v->railtype, totype)) {
 
							/* No power on new rail type, reroute. */
src/road_cmd.cpp
Show inline comments
 
@@ -856,25 +856,25 @@ do_clear:;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		if (ret.Failed()) return ret;
 

	
 
		if (IsNormalRoadTile(tile)) {
 
			/* If the road types don't match, try to convert only if vehicles of
 
			 * the new road type are not powered on the present road type and vehicles of
 
			 * the present road type are powered on the new road type. */
 
			RoadType existing_rt = GetRoadType(tile, rtt);
 
			if (existing_rt != INVALID_ROADTYPE && existing_rt != rt) {
 
				if (HasPowerOnRoad(rt, existing_rt)) {
 
					rt = existing_rt;
 
				} else if (HasPowerOnRoad(existing_rt, rt)) {
 
					CommandCost ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt);
 
					ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
				} else {
 
					return CMD_ERROR;
 
				}
 
			}
 
		}
 
	}
 

	
 
	uint num_pieces = (!need_to_clear && IsTileType(tile, MP_TUNNELBRIDGE)) ?
 
			/* There are 2 pieces on *every* tile of the bridge or tunnel */
 
			2 * (GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2) :
 
@@ -1706,25 +1706,25 @@ static void DrawTile_Road(TileInfo *ti)
 
						default:              image += 4; break; // Paved
 
					}
 
				}
 

	
 
				DrawGroundSprite(image, pal);
 
			}
 

	
 
			DrawRoadOverlays(ti, pal, road_rti, tram_rti, axis, axis);
 

	
 
			/* Draw rail/PBS overlay */
 
			bool draw_pbs = _game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasCrossingReservation(ti->tile);
 
			if (rti->UsesOverlay()) {
 
				PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
 
				pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
 
				SpriteID rail = GetCustomRailSprite(rti, ti->tile, RTSG_CROSSING) + axis;
 
				DrawGroundSprite(rail, pal);
 

	
 
				const Axis road_axis = GetCrossingRoadAxis(ti->tile);
 
				const DiagDirection dir1 = AxisToDiagDir(road_axis);
 
				const DiagDirection dir2 = ReverseDiagDir(dir1);
 
				uint adjacent_diagdirs = 0;
 
				for (DiagDirection dir : { dir1, dir2 }) {
 
					const TileIndex t = TileAddByDiagDir(ti->tile, dir);
 
					if (t < Map::Size() && IsLevelCrossingTile(t) && GetCrossingRoadAxis(t) == road_axis) {
 
						SetBit(adjacent_diagdirs, dir);
 
					}
 
@@ -1748,25 +1748,25 @@ static void DrawTile_Road(TileInfo *ti)
 
						break;
 

	
 
					case (1 << DIAGDIR_NW):
 
						DrawRailTileSeq(ti, &_crossing_layout_SE, TO_CATENARY, rail, 0, PAL_NONE);
 
						break;
 

	
 
					default:
 
						/* Show no sprites */
 
						break;
 
				}
 
			} else if (draw_pbs || tram_rti != nullptr || road_rti->UsesOverlay()) {
 
				/* Add another rail overlay, unless there is only the base road sprite. */
 
				PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
 
				pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
 
				SpriteID rail = GetCrossingRoadAxis(ti->tile) == AXIS_Y ? GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_x : GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_y;
 
				DrawGroundSprite(rail, pal);
 
			}
 

	
 
			/* Draw road, tram catenary */
 
			DrawRoadCatenary(ti);
 

	
 
			/* Draw rail catenary */
 
			if (HasRailCatenaryDrawn(GetRailType(ti->tile))) DrawRailCatenary(ti);
 

	
 
			break;
 
		}
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -375,29 +375,31 @@ static bool FixTTOEngines()
 
		124, 126, 127, 132, 133, 135, 136, 138, 139, 141, 142, 144, 145, 147, 148, 150,
 
		151, 153, 154, 204, 205, 206, 207, 208, 211, 212, 211, 212, 211, 212, 215, 216,
 
		217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
 
		233, 234, 235, 236, 237, 238, 253
 
	};
 

	
 
	for (Vehicle *v : Vehicle::Iterate()) {
 
		if (v->engine_type >= lengthof(tto_to_ttd)) return false;
 
		v->engine_type = tto_to_ttd[v->engine_type];
 
	}
 

	
 
	/* Load the default engine set. Many of them will be overridden later */
 
	uint j = 0;
 
	for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i);
 
	for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i);
 
	for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i);
 
	for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
 
	{
 
		uint j = 0;
 
		for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i);
 
		for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i);
 
		for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i);
 
		for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
 
	}
 

	
 
	Date aging_date = std::min(_date + DAYS_TILL_ORIGINAL_BASE_YEAR, ConvertYMDToDate(2050, 0, 1));
 

	
 
	for (EngineID i = 0; i < 256; i++) {
 
		int oi = ttd_to_tto[i];
 
		Engine *e = GetTempDataEngine(i);
 

	
 
		if (oi == 255) {
 
			/* Default engine is used */
 
			_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
			StartupOneEngine(e, aging_date, 0);
 
			CalcEngineReliability(e, false);
src/station_cmd.cpp
Show inline comments
 
@@ -922,25 +922,25 @@ static CommandCost CheckFlatLandRailStat
 
				TrackBits tracks = GetTrackBits(tile_cur);
 
				Track track = RemoveFirstTrack(&tracks);
 
				Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
 

	
 
				if (tracks == TRACK_BIT_NONE && track == expected_track) {
 
					/* Check for trains having a reservation for this tile. */
 
					if (HasBit(GetRailReservationTrackBits(tile_cur), track)) {
 
						Train *v = GetTrainForReservation(tile_cur, track);
 
						if (v != nullptr) {
 
							affected_vehicles.push_back(v);
 
						}
 
					}
 
					CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track);
 
					ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
					/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
 
					continue;
 
				}
 
			}
 
			ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 
		}
 
	}
 

	
 
@@ -1009,51 +1009,51 @@ static CommandCost CheckFlatLandRoadStop
 
						return_cmd_error(STR_ERROR_DRIVE_THROUGH_JUNCTION);
 
				}
 
			}
 

	
 
			if (build_over_road) {
 
				/* There is a road, check if we can build road+tram stop over it. */
 
				RoadType road_rt = GetRoadType(cur_tile, RTT_ROAD);
 
				if (road_rt != INVALID_ROADTYPE) {
 
					Owner road_owner = GetRoadOwner(cur_tile, RTT_ROAD);
 
					if (road_owner == OWNER_TOWN) {
 
						if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
 
					} else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE) {
 
						CommandCost ret = CheckOwnership(road_owner);
 
						ret = CheckOwnership(road_owner);
 
						if (ret.Failed()) return ret;
 
					}
 
					uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_ROAD));
 

	
 
					if (RoadTypeIsRoad(rt) && !HasPowerOnRoad(rt, road_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
 

	
 
					if (GetDisallowedRoadDirections(cur_tile) != DRD_NONE && road_owner != OWNER_TOWN) {
 
						CommandCost ret = CheckOwnership(road_owner);
 
						ret = CheckOwnership(road_owner);
 
						if (ret.Failed()) return ret;
 
					}
 

	
 
					cost.AddCost(RoadBuildCost(road_rt) * (2 - num_pieces));
 
				} else if (RoadTypeIsRoad(rt)) {
 
					cost.AddCost(RoadBuildCost(rt) * 2);
 
				}
 

	
 
				/* There is a tram, check if we can build road+tram stop over it. */
 
				RoadType tram_rt = GetRoadType(cur_tile, RTT_TRAM);
 
				if (tram_rt != INVALID_ROADTYPE) {
 
					Owner tram_owner = GetRoadOwner(cur_tile, RTT_TRAM);
 
					if (Company::IsValidID(tram_owner) &&
 
							(!_settings_game.construction.road_stop_on_competitor_road ||
 
							/* Disallow breaking end-of-line of someone else
 
							 * so trams can still reverse on this tile. */
 
							HasExactlyOneBit(GetRoadBits(cur_tile, RTT_TRAM)))) {
 
						CommandCost ret = CheckOwnership(tram_owner);
 
						ret = CheckOwnership(tram_owner);
 
						if (ret.Failed()) return ret;
 
					}
 
					uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_TRAM));
 

	
 
					if (RoadTypeIsTram(rt) && !HasPowerOnRoad(rt, tram_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
 

	
 
					cost.AddCost(RoadBuildCost(tram_rt) * (2 - num_pieces));
 
				} else if (RoadTypeIsTram(rt)) {
 
					cost.AddCost(RoadBuildCost(rt) * 2);
 
				}
 
			} else {
 
				ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile);
 
@@ -1299,25 +1299,25 @@ CommandCost CmdBuildRailStation(DoComman
 
	/* Add construction expenses. */
 
	cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
 
	cost.AddCost(numtracks * plat_len * RailBuildCost(rt));
 

	
 
	Station *st = nullptr;
 
	ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
 
	if (ret.Failed()) return ret;
 

	
 
	ret = BuildStationPart(&st, flags, reuse, new_location, STATIONNAMING_RAIL);
 
	if (ret.Failed()) return ret;
 

	
 
	if (st != nullptr && st->train_station.tile != INVALID_TILE) {
 
		CommandCost ret = CanExpandRailStation(st, new_location, axis);
 
		ret = CanExpandRailStation(st, new_location, axis);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* Check if we can allocate a custom stationspec to this station */
 
	const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
 
	int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
 
	if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
 

	
 
	if (statspec != nullptr) {
 
		/* Perform NewStation checks */
 

	
 
		/* Check if the station size is permitted */
 
@@ -1564,25 +1564,25 @@ CommandCost RemoveFromRailBaseStation(Ti
 
		if (!HasStationTileRail(tile)) continue;
 

	
 
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		error.AddCost(ret);
 
		if (ret.Failed()) continue;
 

	
 
		/* Check ownership of station */
 
		T *st = T::GetByTile(tile);
 
		if (st == nullptr) continue;
 

	
 
		if (_current_company != OWNER_WATER) {
 
			CommandCost ret = CheckOwnership(st->owner);
 
			ret = CheckOwnership(st->owner);
 
			error.AddCost(ret);
 
			if (ret.Failed()) continue;
 
		}
 

	
 
		/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
 
		quantity++;
 

	
 
		if (keep_rail || IsStationTileBlocked(tile)) {
 
			/* Don't refund the 'steel' of the track when we keep the
 
			 *  rail, or when the tile didn't have any rail at all. */
 
			total_cost.AddCost(-_price[PR_CLEAR_RAIL]);
 
		}
 
@@ -2227,31 +2227,31 @@ CommandCost CmdBuildAirport(DoCommandFla
 
	if (!as->IsWithinMapBounds(layout, tile)) return CMD_ERROR;
 

	
 
	Direction rotation = as->rotation[layout];
 
	int w = as->size_x;
 
	int h = as->size_y;
 
	if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
 
	TileArea airport_area = TileArea(tile, w, h);
 

	
 
	if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
 
		return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
 
	}
 

	
 
	AirportTileTableIterator iter(as->table[layout], tile);
 
	CommandCost cost = CheckFlatLandAirport(iter, flags);
 
	AirportTileTableIterator tile_iter(as->table[layout], tile);
 
	CommandCost cost = CheckFlatLandAirport(tile_iter, flags);
 
	if (cost.Failed()) return cost;
 

	
 
	/* The noise level is the noise from the airport and reduce it to account for the distance to the town center. */
 
	uint dist;
 
	Town *nearest = AirportGetNearestTown(as, iter, dist);
 
	Town *nearest = AirportGetNearestTown(as, tile_iter, dist);
 
	uint newnoise_level = GetAirportNoiseLevelForDistance(as, dist);
 

	
 
	/* Check if local auth would allow a new airport */
 
	StringID authority_refuse_message = STR_NULL;
 
	Town *authority_refuse_town = nullptr;
 

	
 
	if (_settings_game.economy.station_noise_level) {
 
		/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
 
		if ((nearest->noise_reached + newnoise_level) > nearest->MaxTownNoise()) {
 
			authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE;
 
			authority_refuse_town = nearest;
 
		}
 
@@ -2977,25 +2977,24 @@ draw_default_foundation:
 

	
 
			if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationReservation(ti->tile)) {
 
				SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
 
				DrawGroundSprite(overlay + overlay_offset, PALETTE_CRASH);
 
			}
 
		} else {
 
			image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
 
			if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
 
			DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
 

	
 
			/* PBS debugging, draw reserved tracks darker */
 
			if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationRail(ti->tile) && HasStationReservation(ti->tile)) {
 
				const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
 
				DrawGroundSprite(GetRailStationAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH);
 
			}
 
		}
 
	}
 

	
 
	if (HasStationRail(ti->tile) && HasRailCatenaryDrawn(GetRailType(ti->tile))) DrawRailCatenary(ti);
 

	
 
	if (IsRoadStop(ti->tile)) {
 
		RoadType road_rt = GetRoadTypeRoad(ti->tile);
 
		RoadType tram_rt = GetRoadTypeTram(ti->tile);
 
		const RoadTypeInfo* road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
 
		const RoadTypeInfo* tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
 
@@ -3024,61 +3023,61 @@ draw_default_foundation:
 
		/* Don't offset the waypoint graphics; they're always the same. */
 
		total_offset = 0;
 
	}
 

	
 
	DrawRailTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
 
}
 

	
 
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
 
{
 
	int32 total_offset = 0;
 
	PaletteID pal = COMPANY_SPRITE_COLOUR(_local_company);
 
	const DrawTileSprites *t = GetStationTileLayout(st, image);
 
	const RailtypeInfo *rti = nullptr;
 
	const RailtypeInfo *railtype_info = nullptr;
 

	
 
	if (railtype != INVALID_RAILTYPE) {
 
		rti = GetRailTypeInfo(railtype);
 
		total_offset = rti->GetRailtypeSpriteOffset();
 
		railtype_info = GetRailTypeInfo(railtype);
 
		total_offset = railtype_info->GetRailtypeSpriteOffset();
 
	}
 

	
 
	SpriteID img = t->ground.sprite;
 
	RailTrackOffset overlay_offset;
 
	if (rti != nullptr && rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &img, &overlay_offset)) {
 
		SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND);
 
	if (railtype_info != nullptr && railtype_info->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &img, &overlay_offset)) {
 
		SpriteID ground = GetCustomRailSprite(railtype_info, INVALID_TILE, RTSG_GROUND);
 
		DrawSprite(img, PAL_NONE, x, y);
 
		DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
 
	} else {
 
		DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOUR) ? pal : PAL_NONE, x, y);
 
	}
 

	
 
	if (roadtype != INVALID_ROADTYPE) {
 
		const RoadTypeInfo* rti = GetRoadTypeInfo(roadtype);
 
		const RoadTypeInfo *roadtype_info = GetRoadTypeInfo(roadtype);
 
		if (image >= 4) {
 
			/* Drive-through stop */
 
			uint sprite_offset = 5 - image;
 

	
 
			/* Road underlay takes precedence over tram */
 
			if (rti->UsesOverlay()) {
 
				SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_GROUND);
 
			if (roadtype_info->UsesOverlay()) {
 
				SpriteID ground = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_GROUND);
 
				DrawSprite(ground + sprite_offset, PAL_NONE, x, y);
 

	
 
				SpriteID overlay = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_OVERLAY);
 
				SpriteID overlay = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_OVERLAY);
 
				if (overlay) DrawSprite(overlay + sprite_offset, PAL_NONE, x, y);
 
			} else if (RoadTypeIsTram(roadtype)) {
 
				DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
 
			}
 
		} else {
 
			/* Drive-in stop */
 
			if (RoadTypeIsRoad(roadtype) && rti->UsesOverlay()) {
 
				SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_ROADSTOP);
 
			if (RoadTypeIsRoad(roadtype) && roadtype_info->UsesOverlay()) {
 
				SpriteID ground = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_ROADSTOP);
 
				DrawSprite(ground + image, PAL_NONE, x, y);
 
			}
 
		}
 
	}
 

	
 
	/* Default waypoint has no railtype specific sprites */
 
	DrawRailTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal);
 
}
 

	
 
static int GetSlopePixelZ_Station(TileIndex tile, uint x, uint y)
 
{
 
	return GetTileMaxPixelZ(tile);
src/strgen/strgen.cpp
Show inline comments
 
@@ -463,27 +463,27 @@ int CDECL main(int argc, char *argv[])
 
				}
 
				return 0;
 

	
 
			case 'L':
 
				printf("count\tdescription\tnames\n");
 
				for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
 
					printf("%i\t\"%s\"\t%s\n", pf->plural_count, pf->description, pf->names);
 
				}
 
				return 0;
 

	
 
			case 'P':
 
				printf("name\tflags\tdefault\tdescription\n");
 
				for (size_t i = 0; i < lengthof(_pragmas); i++) {
 
				for (size_t j = 0; j < lengthof(_pragmas); j++) {
 
					printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
 
							_pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]);
 
							_pragmas[j][0], _pragmas[j][1], _pragmas[j][2], _pragmas[j][3]);
 
				}
 
				return 0;
 

	
 
			case 't':
 
				_show_todo |= 1;
 
				break;
 

	
 
			case 'w':
 
				_show_todo |= 2;
 
				break;
 

	
 
			case 'h':
src/strgen/strgen_base.cpp
Show inline comments
 
@@ -868,25 +868,25 @@ static int TranslateArgumentIdx(int argi
 
		strgen_fatal("invalid argidx %d", argidx);
 
	}
 
	const CmdStruct *cs = _cur_pcs.cmd[argidx];
 
	if (cs != nullptr && cs->consumes <= offset) {
 
		strgen_fatal("invalid argidx offset %d:%d", argidx, offset);
 
	}
 

	
 
	if (_cur_pcs.cmd[argidx] == nullptr) {
 
		strgen_fatal("no command for this argidx %d", argidx);
 
	}
 

	
 
	for (int i = sum = 0; i < argidx; i++) {
 
		const CmdStruct *cs = _cur_pcs.cmd[i];
 
		cs = _cur_pcs.cmd[i];
 

	
 
		sum += (cs != nullptr) ? cs->consumes : 1;
 
	}
 

	
 
	return sum + offset;
 
}
 

	
 
static void PutArgidxCommand(Buffer *buffer)
 
{
 
	buffer->AppendUtf8(SCC_ARG_INDEX);
 
	buffer->AppendByte(TranslateArgumentIdx(_cur_argidx));
 
}
src/strings.cpp
Show inline comments
 
@@ -929,25 +929,25 @@ static char *FormatString(char *buff, co
 
						g[p - s] = '\0';
 

	
 
						sub_args_need_free[i] = true;
 
						sub_args.SetParam(i++, (uint64)(size_t)g);
 
					}
 
				}
 
				/* If we didn't error out, we can actually print the string. */
 
				if (*str != '\0') {
 
					str = p;
 
					buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT_START, stringid), &sub_args, last, true);
 
				}
 

	
 
				for (int i = 0; i < 20; i++) {
 
				for (i = 0; i < 20; i++) {
 
					if (sub_args_need_free[i]) free((void *)sub_args.GetParam(i));
 
				}
 
				break;
 
			}
 

	
 
			case SCC_NEWGRF_STRINL: {
 
				StringID substr = Utf8Consume(&str);
 
				str_stack.push(GetStringPtr(substr));
 
				break;
 
			}
 

	
 
			case SCC_NEWGRF_PRINT_WORD_STRING_ID: {
 
@@ -1035,57 +1035,57 @@ static char *FormatString(char *buff, co
 
					str += 3 + (str[1] << 8) + str[2];
 
					num--;
 
				}
 
				break;
 
			}
 

	
 
			case SCC_REVISION: // {REV}
 
				buff = strecpy(buff, _openttd_revision, last);
 
				break;
 

	
 
			case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
 
				if (game_script) break;
 
				const char *str = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
 
				buff = FormatString(buff, str, args, last);
 
				const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
 
				buff = FormatString(buff, raw_string, args, last);
 
				break;
 
			}
 

	
 
			case SCC_STRING: {// {STRING}
 
				StringID str = args->GetInt32(SCC_STRING);
 
				if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
 
				StringID string_id = args->GetInt32(SCC_STRING);
 
				if (game_script && GetStringTab(string_id) != TEXT_TAB_GAMESCRIPT_START) break;
 
				/* WARNING. It's prohibited for the included string to consume any arguments.
 
				 * For included strings that consume argument, you should use STRING1, STRING2 etc.
 
				 * To debug stuff you can set argv to nullptr and it will tell you */
 
				StringParameters tmp_params(args->GetDataPointer(), args->GetDataLeft(), nullptr);
 
				buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
 
				buff = GetStringWithArgs(buff, string_id, &tmp_params, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING1:
 
			case SCC_STRING2:
 
			case SCC_STRING3:
 
			case SCC_STRING4:
 
			case SCC_STRING5:
 
			case SCC_STRING6:
 
			case SCC_STRING7: { // {STRING1..7}
 
				/* Strings that consume arguments */
 
				StringID str = args->GetInt32(b);
 
				if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
 
				StringID string_id = args->GetInt32(b);
 
				if (game_script && GetStringTab(string_id) != TEXT_TAB_GAMESCRIPT_START) break;
 
				uint size = b - SCC_STRING1 + 1;
 
				if (game_script && size > args->GetDataLeft()) {
 
					buff = strecat(buff, "(too many parameters)", last);
 
				} else {
 
					StringParameters sub_args(*args, size);
 
					buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
					buff = GetStringWithArgs(buff, string_id, &sub_args, last, next_substr_case_index, game_script);
 
				}
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_COMMA: // {COMMA}
 
				buff = FormatCommaNumber(buff, args->GetInt64(SCC_COMMA), last);
 
				break;
 

	
 
			case SCC_DECIMAL: {// {DECIMAL}
 
				int64 number = args->GetInt64(SCC_DECIMAL);
 
				int digits = args->GetInt32(SCC_DECIMAL);
 
@@ -1447,41 +1447,41 @@ static char *FormatString(char *buff, co
 
					 * be "drawing" an invalid station is in the case of cargo that is
 
					 * in transit. */
 
					StringParameters tmp_params(nullptr, 0, nullptr);
 
					buff = GetStringWithArgs(buff, STR_UNKNOWN_STATION, &tmp_params, last);
 
					break;
 
				}
 

	
 
				if (!st->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)st->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
 
				} else {
 
					StringID str = st->string_id;
 
					StringID string_id = st->string_id;
 
					if (st->indtype != IT_INVALID) {
 
						/* Special case where the industry provides the name for the station */
 
						const IndustrySpec *indsp = GetIndustrySpec(st->indtype);
 

	
 
						/* Industry GRFs can change which might remove the station name and
 
						 * thus cause very strange things. Here we check for that before we
 
						 * actually set the station name. */
 
						if (indsp->station_name != STR_NULL && indsp->station_name != STR_UNDEFINED) {
 
							str = indsp->station_name;
 
							string_id = indsp->station_name;
 
						}
 
					}
 

	
 
					uint64 args_array[] = {STR_TOWN_NAME, st->town->index, st->index};
 
					WChar types_array[] = {0, SCC_TOWN_NAME, SCC_NUM};
 
					StringParameters tmp_params(args_array, 3, types_array);
 
					buff = GetStringWithArgs(buff, str, &tmp_params, last);
 
					buff = GetStringWithArgs(buff, string_id, &tmp_params, last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_TOWN_NAME: { // {TOWN}
 
				const Town *t = Town::GetIfValid(args->GetInt32(SCC_TOWN_NAME));
 
				if (t == nullptr) break;
 

	
 
				if (!t->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)t->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
 
@@ -1493,58 +1493,58 @@ static char *FormatString(char *buff, co
 

	
 
			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
 
				Waypoint *wp = Waypoint::GetIfValid(args->GetInt32(SCC_WAYPOINT_NAME));
 
				if (wp == nullptr) break;
 

	
 
				if (!wp->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)wp->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
 
				} else {
 
					int64 args_array[] = {wp->town->index, wp->town_cn + 1};
 
					StringParameters tmp_params(args_array);
 
					StringID str = ((wp->string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
 
					if (wp->town_cn != 0) str++;
 
					buff = GetStringWithArgs(buff, str, &tmp_params, last);
 
					StringID string_id = ((wp->string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
 
					if (wp->town_cn != 0) string_id++;
 
					buff = GetStringWithArgs(buff, string_id, &tmp_params, last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_VEHICLE_NAME: { // {VEHICLE}
 
				const Vehicle *v = Vehicle::GetIfValid(args->GetInt32(SCC_VEHICLE_NAME));
 
				if (v == nullptr) break;
 

	
 
				if (!v->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)v->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
 
				} else if (v->group_id != DEFAULT_GROUP) {
 
					/* The vehicle has no name, but is member of a group, so print group name */
 
					int64 args_array[] = {v->group_id, v->unitnumber};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_FORMAT_GROUP_VEHICLE_NAME, &tmp_params, last);
 
				} else {
 
					int64 args_array[] = {v->unitnumber};
 
					StringParameters tmp_params(args_array);
 

	
 
					StringID str;
 
					StringID string_id;
 
					switch (v->type) {
 
						default:           str = STR_INVALID_VEHICLE; break;
 
						case VEH_TRAIN:    str = STR_SV_TRAIN_NAME; break;
 
						case VEH_ROAD:     str = STR_SV_ROAD_VEHICLE_NAME; break;
 
						case VEH_SHIP:     str = STR_SV_SHIP_NAME; break;
 
						case VEH_AIRCRAFT: str = STR_SV_AIRCRAFT_NAME; break;
 
						default:           string_id = STR_INVALID_VEHICLE; break;
 
						case VEH_TRAIN:    string_id = STR_SV_TRAIN_NAME; break;
 
						case VEH_ROAD:     string_id = STR_SV_ROAD_VEHICLE_NAME; break;
 
						case VEH_SHIP:     string_id = STR_SV_SHIP_NAME; break;
 
						case VEH_AIRCRAFT: string_id = STR_SV_AIRCRAFT_NAME; break;
 
					}
 

	
 
					buff = GetStringWithArgs(buff, str, &tmp_params, last);
 
					buff = GetStringWithArgs(buff, string_id, &tmp_params, last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_SIGN_NAME: { // {SIGN}
 
				const Sign *si = Sign::GetIfValid(args->GetInt32());
 
				if (si == nullptr) break;
 

	
 
				if (!si->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)si->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
src/timetable_gui.cpp
Show inline comments
 
@@ -82,33 +82,33 @@ static bool CanDetermineTimeTaken(const 
 
 * @param v Vehicle which must have at least 2 orders.
 
 * @param start order index to start at
 
 * @param travelling Are we still in the travelling part of the start order
 
 * @param table Fill in arrival and departures including intermediate orders
 
 * @param offset Add this value to result and all arrivals and departures
 
 */
 
static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, TimetableArrivalDeparture *table, Ticks offset)
 
{
 
	assert(table != nullptr);
 
	assert(v->GetNumOrders() >= 2);
 
	assert(start < v->GetNumOrders());
 

	
 
	Ticks sum = offset;
 
	VehicleOrderID i = start;
 
	const Order *order = v->GetOrder(i);
 

	
 
	/* Pre-initialize with unknown time */
 
	for (int i = 0; i < v->GetNumOrders(); ++i) {
 
		table[i].arrival = table[i].departure = INVALID_TICKS;
 
	}
 

	
 
	Ticks sum = offset;
 
	VehicleOrderID i = start;
 
	const Order *order = v->GetOrder(i);
 

	
 
	/* Cyclically loop over all orders until we reach the current one again.
 
	 * As we may start at the current order, do a post-checking loop */
 
	do {
 
		/* Automatic orders don't influence the overall timetable;
 
		 * they just add some untimetabled entries, but the time till
 
		 * the next non-implicit order can still be known. */
 
		if (!order->IsType(OT_IMPLICIT)) {
 
			if (travelling || i != start) {
 
				if (!CanDetermineTimeTaken(order, true)) return;
 
				sum += order->GetTimetabledTravel();
 
				table[i].arrival = sum;
 
			}
src/town_cmd.cpp
Show inline comments
 
@@ -84,25 +84,25 @@ void RebuildTownKdtree()
 
 * @param t Town we are interested in
 
 * @return true if town 'owns' a bridge.
 
 */
 
static bool TestTownOwnsBridge(TileIndex tile, const Town *t)
 
{
 
	if (!IsTileOwner(tile, OWNER_TOWN)) return false;
 

	
 
	TileIndex adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
 
	bool town_owned = IsTileType(adjacent, MP_ROAD) && IsTileOwner(adjacent, OWNER_TOWN) && GetTownIndex(adjacent) == t->index;
 

	
 
	if (!town_owned) {
 
		/* Or other adjacent road */
 
		TileIndex adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(GetOtherTunnelBridgeEnd(tile))));
 
		adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(GetOtherTunnelBridgeEnd(tile))));
 
		town_owned = IsTileType(adjacent, MP_ROAD) && IsTileOwner(adjacent, OWNER_TOWN) && GetTownIndex(adjacent) == t->index;
 
	}
 

	
 
	return town_owned;
 
}
 

	
 
Town::~Town()
 
{
 
	if (CleaningPool()) return;
 

	
 
	/* Delete town authority window
 
	 * and remove from list of sorted towns */
 
@@ -2647,33 +2647,33 @@ static bool BuildTownHouse(Town *t, Tile
 
		}
 

	
 
		/* build the house */
 
		t->cache.num_houses++;
 

	
 
		/* Special houses that there can be only one of. */
 
		t->flags |= oneof;
 

	
 
		byte construction_counter = 0;
 
		byte construction_stage = 0;
 

	
 
		if (_generating_world || _game_mode == GM_EDITOR) {
 
			uint32 r = Random();
 
			uint32 construction_random = Random();
 

	
 
			construction_stage = TOWN_HOUSE_COMPLETED;
 
			if (Chance16(1, 7)) construction_stage = GB(r, 0, 2);
 
			if (Chance16(1, 7)) construction_stage = GB(construction_random, 0, 2);
 

	
 
			if (construction_stage == TOWN_HOUSE_COMPLETED) {
 
				ChangePopulation(t, hs->population);
 
			} else {
 
				construction_counter = GB(r, 2, 2);
 
				construction_counter = GB(construction_random, 2, 2);
 
			}
 
		}
 

	
 
		MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
 
		UpdateTownRadius(t);
 
		UpdateTownGrowthRate(t);
 

	
 
		return true;
 
	}
 

	
 
	return false;
 
}
src/train_cmd.cpp
Show inline comments
 
@@ -1193,25 +1193,25 @@ CommandCost CmdMoveRailVehicle(DoCommand
 

	
 
	/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
 
	if (src->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	/* if nothing is selected as destination, try and find a matching vehicle to drag to. */
 
	Train *dst;
 
	if (dest_veh == INVALID_VEHICLE) {
 
		dst = (src->IsEngine() || (flags & DC_AUTOREPLACE)) ? nullptr : FindGoodVehiclePos(src);
 
	} else {
 
		dst = Train::GetIfValid(dest_veh);
 
		if (dst == nullptr) return CMD_ERROR;
 

	
 
		CommandCost ret = CheckOwnership(dst->owner);
 
		ret = CheckOwnership(dst->owner);
 
		if (ret.Failed()) return ret;
 

	
 
		/* Do not allow appending to crashed vehicles, too */
 
		if (dst->vehstatus & VS_CRASHED) return CMD_ERROR;
 
	}
 

	
 
	/* if an articulated part is being handled, deal with its parent vehicle */
 
	src = src->GetFirstEnginePart();
 
	if (dst != nullptr) {
 
		dst = dst->GetFirstEnginePart();
 
	}
 

	
 
@@ -1262,25 +1262,25 @@ CommandCost CmdMoveRailVehicle(DoCommand
 
	 * original_src_head can't be nullptr; src is by definition != nullptr, so src_head can't be nullptr as
 
	 * src->GetFirst() always yields non-nullptr, so eventually original_src_head != nullptr as well. */
 
	bool original_src_head_front_engine = original_src_head->IsFrontEngine();
 
	bool original_dst_head_front_engine = original_dst_head != nullptr && original_dst_head->IsFrontEngine();
 

	
 
	/* (Re)arrange the trains in the wanted arrangement. */
 
	ArrangeTrains(&dst_head, dst, &src_head, src, move_chain);
 

	
 
	if ((flags & DC_AUTOREPLACE) == 0) {
 
		/* If the autoreplace flag is set we do not need to test for the validity
 
		 * because we are going to revert the train to its original state. As we
 
		 * assume the original state was correct autoreplace can skip this. */
 
		CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true);
 
		ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true);
 
		if (ret.Failed()) {
 
			/* Restore the train we had. */
 
			RestoreTrainBackup(original_src);
 
			RestoreTrainBackup(original_dst);
 
			return ret;
 
		}
 
	}
 

	
 
	/* do it? */
 
	if (flags & DC_EXEC) {
 
		/* Remove old heads from the statistics */
 
		if (original_src_head_front_engine) GroupStatistics::CountVehicle(original_src_head, -1);
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -853,25 +853,25 @@ static CommandCost DoClearTunnel(TileInd
 

	
 
	ret = TunnelBridgeIsFree(tile, endtile);
 
	if (ret.Failed()) return ret;
 

	
 
	_build_tunnel_endtile = endtile;
 

	
 
	Town *t = nullptr;
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
 

	
 
		/* Check if you are allowed to remove the tunnel owned by a town
 
		 * Removal depends on difficulty settings */
 
		CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
 
		ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
	 * you have a "Poor" (0) town rating */
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
 
	}
 

	
 
	Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_TUNNEL);
 
	uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
 

	
 
@@ -934,25 +934,25 @@ static CommandCost DoClearBridge(TileInd
 
	ret = TunnelBridgeIsFree(tile, endtile);
 
	if (ret.Failed()) return ret;
 

	
 
	DiagDirection direction = GetTunnelBridgeDirection(tile);
 
	TileIndexDiff delta = TileOffsByDiagDir(direction);
 

	
 
	Town *t = nullptr;
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
 

	
 
		/* Check if you are allowed to remove the bridge owned by a town
 
		 * Removal depends on difficulty settings */
 
		CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
 
		ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
	 * you have a "Poor" (0) town rating */
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
 
	}
 

	
 
	Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_BRIDGE);
 
	uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -3217,26 +3217,26 @@ public:
 

	
 
		/* Widget WID_VV_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
 
		 * Widget WID_VV_CLONE_VEH should then be shown, since cloning is allowed only while in depot and stopped.
 
		 */
 
		PlaneSelections plane = veh_stopped ? SEL_DC_CLONE : SEL_DC_GOTO_DEPOT;
 
		NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
 
		if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
 
			this->SelectPlane(plane);
 
			this->SetWidgetDirty(WID_VV_SELECT_DEPOT_CLONE);
 
		}
 
		/* The same system applies to widget WID_VV_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
 
		if (v->IsGroundVehicle()) {
 
			PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
 
			NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN);
 
			plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
 
			nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN);
 
			if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {
 
				this->SelectPlane(plane);
 
				this->SetWidgetDirty(WID_VV_SELECT_REFIT_TURN);
 
			}
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
src/video/opengl.cpp
Show inline comments
 
@@ -1111,26 +1111,26 @@ void OpenGLBackend::PopulateCursorCache(
 
	this->cursor_pos = _cursor.pos;
 
	this->cursor_sprite_count = _cursor.sprite_count;
 
	this->cursor_in_window = _cursor.in_window;
 

	
 
	for (uint i = 0; i < _cursor.sprite_count; ++i) {
 
		this->cursor_sprite_seq[i] = _cursor.sprite_seq[i];
 
		this->cursor_sprite_pos[i] = _cursor.sprite_pos[i];
 
		SpriteID sprite = _cursor.sprite_seq[i].sprite;
 

	
 
		if (!this->cursor_cache.Contains(sprite)) {
 
			Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, ST_NORMAL, &SimpleSpriteAlloc, this));
 
			if (old != nullptr) {
 
				OpenGLSprite *sprite = (OpenGLSprite *)old->data;
 
				sprite->~OpenGLSprite();
 
				OpenGLSprite *gl_sprite = (OpenGLSprite *)old->data;
 
				gl_sprite->~OpenGLSprite();
 
				free(old);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Clear all cached cursor sprites.
 
 */
 
void OpenGLBackend::InternalClearCursorCache()
 
{
 
	Sprite *sp;
src/viewport.cpp
Show inline comments
 
@@ -1347,70 +1347,70 @@ static Rect ExpandRectWithViewportSignMa
 

	
 
static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi)
 
{
 
	Rect search_rect{ dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height };
 
	search_rect = ExpandRectWithViewportSignMargins(search_rect, dpi->zoom);
 

	
 
	bool show_stations = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && _game_mode != GM_MENU;
 
	bool show_waypoints = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && _game_mode != GM_MENU;
 
	bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _game_mode != GM_MENU;
 
	bool show_signs = HasBit(_display_opt, DO_SHOW_SIGNS) && !IsInvisibilitySet(TO_SIGNS);
 
	bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS);
 

	
 
	const BaseStation *st;
 
	const Sign *si;
 

	
 
	/* Collect all the items first and draw afterwards, to ensure layering */
 
	std::vector<const BaseStation *> stations;
 
	std::vector<const Town *> towns;
 
	std::vector<const Sign *> signs;
 

	
 
	_viewport_sign_kdtree.FindContained(search_rect.left, search_rect.top, search_rect.right, search_rect.bottom, [&](const ViewportSignKdtreeItem & item) {
 
		switch (item.type) {
 
			case ViewportSignKdtreeItem::VKI_STATION:
 
			case ViewportSignKdtreeItem::VKI_STATION: {
 
				if (!show_stations) break;
 
				st = BaseStation::Get(item.id.station);
 
				const BaseStation *st = BaseStation::Get(item.id.station);
 

	
 
				/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
 
				if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
 

	
 
				stations.push_back(st);
 
				break;
 

	
 
			case ViewportSignKdtreeItem::VKI_WAYPOINT:
 
			}
 

	
 
			case ViewportSignKdtreeItem::VKI_WAYPOINT: {
 
				if (!show_waypoints) break;
 
				st = BaseStation::Get(item.id.station);
 
				const BaseStation *st = BaseStation::Get(item.id.station);
 

	
 
				/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
 
				if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
 

	
 
				stations.push_back(st);
 
				break;
 
			}
 

	
 
			case ViewportSignKdtreeItem::VKI_TOWN:
 
				if (!show_towns) break;
 
				towns.push_back(Town::Get(item.id.town));
 
				break;
 

	
 
			case ViewportSignKdtreeItem::VKI_SIGN:
 
			case ViewportSignKdtreeItem::VKI_SIGN: {
 
				if (!show_signs) break;
 
				si = Sign::Get(item.id.sign);
 
				const Sign *si = Sign::Get(item.id.sign);
 

	
 
				/* Don't draw if sign is owned by another company and competitor signs should be hidden.
 
				* Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt
 
				* companies can leave OWNER_NONE signs after them. */
 
				if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
 

	
 
				signs.push_back(si);
 
				break;
 
			}
 

	
 
			default:
 
				NOT_REACHED();
 
		}
 
	});
 

	
 
	/* Layering order (bottom to top): Town names, signs, stations */
 

	
 
	for (const auto *t : towns) {
 
		ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->cache.sign,
 
			_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
 
			STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK,
src/water_cmd.cpp
Show inline comments
 
@@ -255,25 +255,25 @@ void MakeWaterKeepingClass(TileIndex til
 

	
 
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckTileOwnership(tile);
 
	if (ret.Failed()) return ret;
 

	
 
	TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
	/* do not check for ship on tile when company goes bankrupt */
 
	if (!(flags & DC_BANKRUPT)) {
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret = EnsureNoVehicleOnGround(tile);
 
		if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		delete Depot::GetByTile(tile);
 

	
 
		Company *c = Company::GetIfValid(GetTileOwner(tile));
 
		if (c != nullptr) {
 
			c->infrastructure.water -= 2 * LOCK_DEPOT_TILE_FACTOR;
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 
@@ -530,25 +530,25 @@ static CommandCost ClearTile_Water(TileI
 
			/* Make sure freeform edges are allowed or it's not an edge tile. */
 
			if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, Map::MaxX() - 1) ||
 
					!IsInsideMM(TileY(tile), 1, Map::MaxY() - 1))) {
 
				return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
 
			}
 

	
 
			/* Make sure no vehicle is on the tile */
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			if (ret.Failed()) return ret;
 

	
 
			Owner owner = GetTileOwner(tile);
 
			if (owner != OWNER_WATER && owner != OWNER_NONE) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				ret = CheckTileOwnership(tile);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				if (IsCanal(tile) && Company::IsValidID(owner)) {
 
					Company::Get(owner)->infrastructure.water--;
 
					DirtyCompanyInfrastructureWindows(owner);
 
				}
 
				DoClearSquare(tile);
 
				MarkCanalsAndRiversAroundDirty(tile);
 
			}
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -208,29 +208,29 @@ CommandCost CmdBuildRailWaypoint(DoComma
 
	if (ret.Failed()) return ret;
 

	
 
	/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
 
	TileIndex center_tile = start_tile + (count / 2) * offset;
 
	if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
 

	
 
	if (wp != nullptr) {
 
		/* Reuse an existing waypoint. */
 
		if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
 

	
 
		/* check if we want to expand an already existing waypoint? */
 
		if (wp->train_station.tile != INVALID_TILE) {
 
			CommandCost ret = CanExpandRailStation(wp, new_location, axis);
 
			ret = CanExpandRailStation(wp, new_location, axis);
 
			if (ret.Failed()) return ret;
 
		}
 

	
 
		CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
 
		ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
 
		if (ret.Failed()) return ret;
 
	} else {
 
		/* allocate and initialize new waypoint */
 
		if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (wp == nullptr) {
 
			wp = new Waypoint(start_tile);
 
		} else if (!wp->IsInUse()) {
 
			/* Move existing (recently deleted) waypoint to the new location */
 
			wp->xy = start_tile;
src/widget.cpp
Show inline comments
 
@@ -3200,25 +3200,25 @@ static int MakeWidgetTree(const NWidgetP
 
		int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
 
		parts += num_used;
 
		total_used += num_used;
 

	
 
		/* Break out of loop when end reached */
 
		if (sub_widget == nullptr) break;
 

	
 
		/* If sub-widget is a container, recursively fill that container. */
 
		WidgetType tp = sub_widget->type;
 
		if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
 
							|| tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) {
 
			NWidgetBase *sub_ptr = sub_widget;
 
			int num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
 
			num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
 
			parts += num_used;
 
			total_used += num_used;
 
		}
 

	
 
		/* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
 
		if (nwid_cont != nullptr) nwid_cont->Add(sub_widget);
 
		if (nwid_parent != nullptr) nwid_parent->Add(sub_widget);
 
		if (nwid_cont == nullptr && nwid_parent == nullptr) {
 
			*parent = sub_widget;
 
			return total_used;
 
		}
 
	}
src/window.cpp
Show inline comments
 
@@ -248,25 +248,25 @@ void Window::SetWidgetHighlight(byte wid
 
	if (nwid == nullptr) return;
 

	
 
	nwid->SetHighlighted(highlighted_colour);
 
	this->SetWidgetDirty(widget_index);
 

	
 
	if (highlighted_colour != TC_INVALID) {
 
		/* If we set a highlight, the window has a highlight */
 
		this->flags |= WF_HIGHLIGHTED;
 
	} else {
 
		/* If we disable a highlight, check all widgets if anyone still has a highlight */
 
		bool valid = false;
 
		for (uint i = 0; i < this->nested_array_size; i++) {
 
			NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
 
			nwid = this->GetWidget<NWidgetBase>(i);
 
			if (nwid == nullptr) continue;
 
			if (!nwid->IsHighlighted()) continue;
 

	
 
			valid = true;
 
		}
 
		/* If nobody has a highlight, disable the flag on the window */
 
		if (!valid) CLRBITS(this->flags, WF_HIGHLIGHTED);
 
	}
 
}
 

	
 
/**
 
 * Gets the highlighted status of a widget.
0 comments (0 inline, 0 general)