Files @ r19069:69fb59a39060
Branch filter:

Location: cpp/openttd-patchpack/source/src/road.cpp - annotation

rubidium
(svn r23937) -Change: improve the wording of some of the timeout related "error" messages
r8091:d63ba361d6b8
r8091:d63ba361d6b8
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r9111:983de9c5a848
r9111:983de9c5a848
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r8236:a2ecfe92ab23
r10208:ef8fcc3dc4ca
r10208:ef8fcc3dc4ca
r9070:e059c65164f3
r10960:e97ebf9cf99b
r11108:1df88c46bf05
r7641:2b26b5be3fd7
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r13499:0af2aac7f5aa
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r11904:2acd21e9a0b6
r11108:1df88c46bf05
r18248:133cf25ab512
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r10956:5bfc69fc5e37
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r15594:ba7e42fbae24
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r14450:8f83ebfe28cc
r7641:2b26b5be3fd7
r15608:7b580ec7448a
r15608:7b580ec7448a
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r7641:2b26b5be3fd7
r8236:a2ecfe92ab23
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r10207:a1fc2f2a33db
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r18771:b0bbffcb9160
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r11944:3b8f9f948e8d
r11944:3b8f9f948e8d
r11944:3b8f9f948e8d
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r10207:a1fc2f2a33db
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r10207:a1fc2f2a33db
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r9070:e059c65164f3
r9070:e059c65164f3
r9070:e059c65164f3
r8236:a2ecfe92ab23
r9413:fcf267325763
r10744:a93a9430d707
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
r8236:a2ecfe92ab23
/* $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 road.cpp Generic road related functions. */

#include "stdafx.h"
#include "rail_map.h"
#include "road_map.h"
#include "water_map.h"
#include "genworld.h"
#include "company_func.h"
#include "company_base.h"
#include "engine_base.h"
#include "date_func.h"
#include "landscape.h"

/**
 * Return if the tile is a valid tile for a crossing.
 *
 * @param tile the curent tile
 * @param ax the axis of the road over the rail
 * @return true if it is a valid tile
 */
static bool IsPossibleCrossing(const TileIndex tile, Axis ax)
{
	return (IsTileType(tile, MP_RAILWAY) &&
		GetRailTileType(tile) == RAIL_TILE_NORMAL &&
		GetTrackBits(tile) == (ax == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) &&
		GetFoundationSlope(tile) == SLOPE_FLAT);
}

/**
 * Clean up unneccesary RoadBits of a planed tile.
 * @param tile current tile
 * @param org_rb planed RoadBits
 * @return optimised RoadBits
 */
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
{
	if (!IsValidTile(tile)) return ROAD_NONE;
	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
		const TileIndex neighbor_tile = TileAddByDiagDir(tile, dir);

		/* Get the Roadbit pointing to the neighbor_tile */
		const RoadBits target_rb = DiagDirToRoadBits(dir);

		/* If the roadbit is in the current plan */
		if (org_rb & target_rb) {
			bool connective = false;
			const RoadBits mirrored_rb = MirrorRoadBits(target_rb);

			switch (GetTileType(neighbor_tile)) {
				/* Allways connective ones */
				case MP_CLEAR: case MP_TREES:
					connective = true;
					break;

				/* The conditionally connective ones */
				case MP_TUNNELBRIDGE:
				case MP_STATION:
				case MP_ROAD: {
					const RoadBits neighbor_rb = GetAnyRoadBits(neighbor_tile, ROADTYPE_ROAD) | GetAnyRoadBits(neighbor_tile, ROADTYPE_TRAM);

					/* Accept only connective tiles */
					connective = (neighbor_rb & mirrored_rb) || // Neighbor has got the fitting RoadBit
							HasExactlyOneBit(neighbor_rb); // Neighbor has got only one Roadbit

					break;
				}

				case MP_RAILWAY:
					connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir));
					break;

				case MP_WATER:
					/* Check for real water tile */
					connective = !IsWater(neighbor_tile);
					break;

				/* The defentetly not connective ones */
				default: break;
			}

			/* If the neighbor tile is inconnective remove the planed road connection to it */
			if (!connective) org_rb ^= target_rb;

		}
	}

	return org_rb;
}

/**
 * Finds out, whether given company has all given RoadTypes available
 * @param company ID of company
 * @param rts RoadTypes to test
 * @return true if company has all requested RoadTypes available
 */
bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts)
{
	RoadTypes avail_roadtypes;

	if (company == OWNER_DEITY || company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) {
		avail_roadtypes = ROADTYPES_ROAD;
	} else {
		Company *c = Company::GetIfValid(company);
		if (c == NULL) return false;
		avail_roadtypes = (RoadTypes)c->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
	}
	return (rts & ~avail_roadtypes) == 0;
}

/**
 * Validate functions for rail building.
 * @param rt road type to check.
 * @return true if the current company may build the road.
 */
bool ValParamRoadType(const RoadType rt)
{
	return HasRoadTypesAvail(_current_company, RoadTypeToRoadTypes(rt));
}

/**
 * Get the road types the given company can build.
 * @param company the company to get the roadtypes for.
 * @return the road types.
 */
RoadTypes GetCompanyRoadtypes(CompanyID company)
{
	RoadTypes rt = ROADTYPES_NONE;

	Engine *e;
	FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
		const EngineInfo *ei = &e->info;

		if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
				(HasBit(e->company_avail, company) || _date >= e->intro_date + DAYS_IN_YEAR)) {
			SetBit(rt, HasBit(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
		}
	}

	return rt;
}