Changeset - r18771:b0bbffcb9160
[Not reviewed]
master
0 14 0
truebrain - 12 years ago 2011-12-19 21:02:33
truebrain@openttd.org
(svn r23629) -Add: allow ScriptRoad::BuildRoad, ScriptBridge::BuildBridge (for roads) and ScriptTunnel:BuildTunnel (for roads) to work for GameScript
14 files changed with 81 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -194,14 +194,14 @@ static const Command _command_proc_table
 
	DEF_CMD(CmdBuildSingleRail,          CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SINGLE_RAIL
 
	DEF_CMD(CmdRemoveSingleRail,                        CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_SINGLE_RAIL
 
	DEF_CMD(CmdLandscapeClear,                                 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LANDSCAPE_CLEAR
 
	DEF_CMD(CmdBuildBridge,              CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_BRIDGE
 
	DEF_CMD(CmdBuildBridge,  CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_BRIDGE
 
	DEF_CMD(CmdBuildRailStation,         CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_STATION
 
	DEF_CMD(CmdBuildTrainDepot,          CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TRAIN_DEPOT
 
	DEF_CMD(CmdBuildSingleSignal,                       CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SIGNALS
 
	DEF_CMD(CmdRemoveSingleSignal,                      CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_SIGNALS
 
	DEF_CMD(CmdTerraformLand,           CMD_ALL_TILES | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_TERRAFORM_LAND
 
	DEF_CMD(CmdBuildObject,              CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_OBJECT
 
	DEF_CMD(CmdBuildTunnel,                             CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TUNNEL
 
	DEF_CMD(CmdBuildTunnel,                 CMD_DEITY | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TUNNEL
 
	DEF_CMD(CmdRemoveFromRailStation,                          0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_STATION
 
	DEF_CMD(CmdConvertRail,                                    0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAILD
 
	DEF_CMD(CmdBuildRailWaypoint,                              0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_WAYPOINT
 
@@ -210,9 +210,9 @@ static const Command _command_proc_table
 

	
 
	DEF_CMD(CmdBuildRoadStop,            CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_STOP
 
	DEF_CMD(CmdRemoveRoadStop,                                 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_ROAD_STOP
 
	DEF_CMD(CmdBuildLongRoad,            CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_LONG_ROAD
 
	DEF_CMD(CmdBuildLongRoad,CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_LONG_ROAD
 
	DEF_CMD(CmdRemoveLongRoad,            CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_LONG_ROAD; towns may disallow removing road bits (as they are connected) in test, but in exec they're removed and thus removing is allowed.
 
	DEF_CMD(CmdBuildRoad,                CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD
 
	DEF_CMD(CmdBuildRoad,    CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD
 
	DEF_CMD(CmdBuildRoadDepot,           CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_DEPOT
 

	
 
	DEF_CMD(CmdBuildAirport,             CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_AIRPORT
src/road.cpp
Show inline comments
 
@@ -106,7 +106,7 @@ bool HasRoadTypesAvail(const CompanyID c
 
{
 
	RoadTypes avail_roadtypes;
 

	
 
	if (company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) {
 
	if (company == OWNER_DEITY || company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) {
 
		avail_roadtypes = ROADTYPES_ROAD;
 
	} else {
 
		Company *c = Company::GetIfValid(company);
src/road_cmd.cpp
Show inline comments
 
@@ -478,6 +478,7 @@ static CommandCost CheckRoadSlope(Slope 
 
 */
 
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyID company = _current_company;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	RoadBits existing = ROAD_NONE;
 
@@ -485,10 +486,19 @@ CommandCost CmdBuildRoad(TileIndex tile,
 

	
 
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
 
	 * if a non-company is building the road */
 
	if ((Company::IsValidID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !Town::IsValidID(p2))) return CMD_ERROR;
 
	if (_current_company != OWNER_TOWN) {
 
	if ((Company::IsValidID(company) && p2 != 0) || (company == OWNER_TOWN && !Town::IsValidID(p2)) || (company == OWNER_DEITY && p2 != 0)) return CMD_ERROR;
 
	if (company != OWNER_TOWN) {
 
		const Town *town = CalcClosestTownFromTile(tile);
 
		p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN;
 

	
 
		if (company == OWNER_DEITY) {
 
			company = OWNER_TOWN;
 

	
 
			/* If we are not within a town, we are not owned by the town */
 
			if (town == NULL || DistanceSquare(tile, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
 
				company = OWNER_NONE;
 
			}
 
		}
 
	}
 

	
 
	RoadBits pieces = Extract<RoadBits, 0, 4>(p1);
 
@@ -608,11 +618,11 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
				Track railtrack = AxisToTrack(OtherAxis(roaddir));
 
				YapfNotifyTrackLayoutChange(tile, railtrack);
 
				/* Update company infrastructure counts. A level crossing has two road bits. */
 
				Company *c = Company::GetIfValid(_current_company);
 
				Company *c = Company::GetIfValid(company);
 
				if (c != NULL) {
 
					c->infrastructure.road[rt] += 2;
 
					if (rt != ROADTYPE_ROAD) c->infrastructure.road[ROADTYPE_ROAD] += 2;
 
					DirtyCompanyInfrastructureWindows(_current_company);
 
					DirtyCompanyInfrastructureWindows(company);
 
				}
 
				/* Update rail count for level crossings. The plain track is already
 
				 * counted, so only add the difference to the level crossing cost. */
 
@@ -621,7 +631,7 @@ CommandCost CmdBuildRoad(TileIndex tile,
 

	
 
				/* Always add road to the roadtypes (can't draw without it) */
 
				bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
 
				MakeRoadCrossing(tile, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
 
				MakeRoadCrossing(tile, company, company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
 
				SetCrossingReservation(tile, reserved);
 
				UpdateLevelCrossing(tile, false);
 
				MarkTileDirtyByTile(tile);
 
@@ -717,7 +727,7 @@ do_clear:;
 
				RoadTileType rtt = GetRoadTileType(tile);
 
				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
 
					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
 
					SetRoadOwner(tile, rt, _current_company);
 
					SetRoadOwner(tile, rt, company);
 
					if (rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
 
				}
 
				if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
 
@@ -729,8 +739,8 @@ do_clear:;
 

	
 
				SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
 
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
 
				SetRoadOwner(other_end, rt, _current_company);
 
				SetRoadOwner(tile, rt, _current_company);
 
				SetRoadOwner(other_end, rt, company);
 
				SetRoadOwner(tile, rt, company);
 

	
 
				/* Mark tiles dirty that have been repaved */
 
				MarkTileDirtyByTile(other_end);
 
@@ -746,11 +756,11 @@ do_clear:;
 
			case MP_STATION:
 
				assert(IsDriveThroughStopTile(tile));
 
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
 
				SetRoadOwner(tile, rt, _current_company);
 
				SetRoadOwner(tile, rt, company);
 
				break;
 

	
 
			default:
 
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_company, _current_company);
 
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, company, company);
 
				break;
 
		}
 

	
src/script/api/game/game_bridge.hpp.sq
Show inline comments
 
@@ -42,6 +42,7 @@ void SQGSBridge_Register(Squirrel *engin
 
	SQGSBridge.DefSQStaticMethod(engine, &ScriptBridge::GetPrice,          "GetPrice",          3, ".ii");
 
	SQGSBridge.DefSQStaticMethod(engine, &ScriptBridge::GetMaxLength,      "GetMaxLength",      2, ".i");
 
	SQGSBridge.DefSQStaticMethod(engine, &ScriptBridge::GetMinLength,      "GetMinLength",      2, ".i");
 
	SQGSBridge.DefSQStaticMethod(engine, &ScriptBridge::BuildBridge,       "BuildBridge",       5, ".iiii");
 
	SQGSBridge.DefSQStaticMethod(engine, &ScriptBridge::GetOtherBridgeEnd, "GetOtherBridgeEnd", 2, ".i");
 

	
 
	SQGSBridge.PostRegister(engine);
src/script/api/game/game_road.hpp.sq
Show inline comments
 
@@ -59,6 +59,8 @@ void SQGSRoad_Register(Squirrel *engine)
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetRoadDepotFrontTile,         "GetRoadDepotFrontTile",         2, ".i");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetRoadStationFrontTile,       "GetRoadStationFrontTile",       2, ".i");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetDriveThroughBackTile,       "GetDriveThroughBackTile",       2, ".i");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::BuildRoad,                     "BuildRoad",                     3, ".ii");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::BuildRoadFull,                 "BuildRoadFull",                 3, ".ii");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetBuildCost,                  "GetBuildCost",                  3, ".ii");
 
	SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaintenanceCostFactor,      "GetMaintenanceCostFactor",      2, ".i");
 

	
src/script/api/game/game_tile.hpp.sq
Show inline comments
 
@@ -77,6 +77,7 @@ void SQGSTile_Register(Squirrel *engine)
 
	ScriptError::RegisterErrorMapString(ScriptTile::ERR_AREA_ALREADY_FLAT,       "ERR_AREA_ALREADY_FLAT");
 
	ScriptError::RegisterErrorMapString(ScriptTile::ERR_EXCAVATION_WOULD_DAMAGE, "ERR_EXCAVATION_WOULD_DAMAGE");
 

	
 
	SQGSTile.DefSQStaticMethod(engine, &ScriptTile::IsBuildable,                "IsBuildable",                2, ".i");
 
	SQGSTile.DefSQStaticMethod(engine, &ScriptTile::IsBuildableRectangle,       "IsBuildableRectangle",       4, ".iii");
 
	SQGSTile.DefSQStaticMethod(engine, &ScriptTile::IsWaterTile,                "IsWaterTile",                2, ".i");
 
	SQGSTile.DefSQStaticMethod(engine, &ScriptTile::IsCoastTile,                "IsCoastTile",                2, ".i");
src/script/api/game/game_tunnel.hpp.sq
Show inline comments
 
@@ -39,6 +39,7 @@ void SQGSTunnel_Register(Squirrel *engin
 

	
 
	SQGSTunnel.DefSQStaticMethod(engine, &ScriptTunnel::IsTunnelTile,      "IsTunnelTile",      2, ".i");
 
	SQGSTunnel.DefSQStaticMethod(engine, &ScriptTunnel::GetOtherTunnelEnd, "GetOtherTunnelEnd", 2, ".i");
 
	SQGSTunnel.DefSQStaticMethod(engine, &ScriptTunnel::BuildTunnel,       "BuildTunnel",       3, ".ii");
 

	
 
	SQGSTunnel.PostRegister(engine);
 
}
src/script/api/script_bridge.cpp
Show inline comments
 
@@ -17,6 +17,7 @@
 
#include "../../strings_func.h"
 
#include "../../economy_func.h"
 
#include "../../date_func.h"
 
#include "../../company_func.h"
 

	
 
/* static */ bool ScriptBridge::IsValidBridge(BridgeID bridge_id)
 
{
 
@@ -74,6 +75,7 @@ static void _DoCommandReturnBuildBridge1
 
	EnforcePrecondition(false, TileX(start) == TileX(end) || TileY(start) == TileY(end));
 
	EnforcePrecondition(false, vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER);
 
	EnforcePrecondition(false, vehicle_type != ScriptVehicle::VT_RAIL || ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType()));
 
	EnforcePrecondition(false, _current_company != OWNER_DEITY || vehicle_type == ScriptVehicle::VT_ROAD);
 

	
 
	uint type = 0;
 
	switch (vehicle_type) {
src/script/api/script_bridge.hpp
Show inline comments
 
@@ -135,6 +135,7 @@ public:
 
	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
 
	 * @pre vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_WATER ||
 
	 *   (vehicle_type == ScriptVehicle::VT_RAIL && ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())).
 
	 * @game @pre Outside CompanyMode: vehicle_type == ScriptVehicle::VT_ROAD.
 
	 * @exception ScriptError::ERR_ALREADY_BUILT
 
	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
 
	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
 
@@ -143,9 +144,9 @@ public:
 
	 * @exception ScriptBridge::ERR_BRIDGE_CANNOT_END_IN_WATER
 
	 * @exception ScriptBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
 
	 * @return Whether the bridge has been/can be build or not.
 
	 * @game @note Building a bridge (without CompanyMode) results in a bridge owned by towns.
 
	 * @note No matter if the road pieces were build or not, if building the
 
	 *  bridge succeeded, this function returns true.
 
	 * @api -game
 
	 */
 
	static bool BuildBridge(ScriptVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end);
 

	
src/script/api/script_road.hpp
Show inline comments
 
@@ -265,8 +265,8 @@ public:
 
	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
 
	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
 
	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 
	 * @game @note Building a piece of road (without CompanyMode) results in a piece of road owned by towns.
 
	 * @return Whether the road has been/can be build or not.
 
	 * @api -game
 
	 */
 
	static bool BuildRoad(TileIndex start, TileIndex end);
 

	
 
@@ -317,8 +317,8 @@ public:
 
	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
 
	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
 
	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 
	 * @game @note Building a piece of road (without CompanyMode) results in a piece of road owned by towns.
 
	 * @return Whether the road has been/can be build or not.
 
	 * @api -game
 
	 */
 
	static bool BuildRoadFull(TileIndex start, TileIndex end);
 

	
src/script/api/script_tile.hpp
Show inline comments
 
@@ -130,7 +130,6 @@ public:
 
	 *   as you can build tram-rails on road-tiles.
 
	 * @note For rail you also might want to check for ScriptRoad::IsRoad(),
 
	 *   as in some cases you can build rails on road-tiles.
 
	 * @api -game
 
	 */
 
	static bool IsBuildable(TileIndex tile);
 

	
src/script/api/script_tunnel.cpp
Show inline comments
 
@@ -15,6 +15,7 @@
 
#include "../script_instance.hpp"
 
#include "../../tunnel_map.h"
 
#include "../../command_func.h"
 
#include "../../company_func.h"
 

	
 
/* static */ bool ScriptTunnel::IsTunnelTile(TileIndex tile)
 
{
 
@@ -83,6 +84,7 @@ static void _DoCommandReturnBuildTunnel1
 
	EnforcePrecondition(false, ::IsValidTile(start));
 
	EnforcePrecondition(false, vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_ROAD);
 
	EnforcePrecondition(false, vehicle_type != ScriptVehicle::VT_RAIL || ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType()));
 
	EnforcePrecondition(false, _current_company != OWNER_DEITY || vehicle_type == ScriptVehicle::VT_ROAD);
 

	
 
	uint type = 0;
 
	if (vehicle_type == ScriptVehicle::VT_ROAD) {
src/script/api/script_tunnel.hpp
Show inline comments
 
@@ -87,6 +87,7 @@ public:
 
	 * @pre ScriptMap::IsValidTile(start).
 
	 * @pre vehicle_type == ScriptVehicle::VT_ROAD || (vehicle_type == ScriptVehicle::VT_RAIL &&
 
	 *   ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())).
 
	 * @game @pre Outside CompanyMode: vehicle_type == ScriptVehicle::VT_ROAD.
 
	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
 
	 * @exception ScriptTunnel::ERR_TUNNEL_CANNOT_BUILD_ON_WATER
 
	 * @exception ScriptTunnel::ERR_TUNNEL_START_SITE_UNSUITABLE
 
@@ -96,7 +97,7 @@ public:
 
	 * @note The slope of a tile can be determined by ScriptTile::GetSlope(TileIndex).
 
	 * @note No matter if the road pieces were build or not, if building the
 
	 *  tunnel succeeded, this function returns true.
 
	 * @api -game
 
	 * @game @note Building a bridge (without CompanyMode) results in a bridge owned by towns.
 
	 */
 
	static bool BuildTunnel(ScriptVehicle::VehicleType vehicle_type, TileIndex start);
 

	
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -212,6 +212,8 @@ CommandCost CheckBridgeAvailability(Brid
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyID company = _current_company;
 

	
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadTypes roadtypes = ROADTYPES_NONE;
 

	
 
@@ -226,7 +228,7 @@ CommandCost CmdBuildBridge(TileIndex end
 
	switch (transport_type) {
 
		case TRANSPORT_ROAD:
 
			roadtypes = Extract<RoadTypes, 8, 2>(p2);
 
			if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(_current_company, roadtypes)) return CMD_ERROR;
 
			if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(company, roadtypes)) return CMD_ERROR;
 
			break;
 

	
 
		case TRANSPORT_RAIL:
 
@@ -244,6 +246,18 @@ CommandCost CmdBuildBridge(TileIndex end
 
	TileIndex tile_start = p1;
 
	TileIndex tile_end = end_tile;
 

	
 
	if (company == OWNER_DEITY) {
 
		if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
 
		const Town *town = CalcClosestTownFromTile(tile_start);
 

	
 
		company = OWNER_TOWN;
 

	
 
		/* If we are not within a town, we are not owned by the town */
 
		if (town == NULL || DistanceSquare(tile_start, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
 
			company = OWNER_NONE;
 
		}
 
	}
 

	
 
	if (tile_start == tile_end) {
 
		return_cmd_error(STR_ERROR_CAN_T_START_AND_END_ON);
 
	}
 
@@ -312,7 +326,7 @@ CommandCost CmdBuildBridge(TileIndex end
 
		}
 

	
 
		/* Do not allow replacing another company's bridges. */
 
		if (!IsTileOwner(tile_start, _current_company) && !IsTileOwner(tile_start, OWNER_TOWN)) {
 
		if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN)) {
 
			return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
 
		}
 

	
 
@@ -424,7 +438,7 @@ CommandCost CmdBuildBridge(TileIndex end
 
			}
 
		}
 

	
 
		owner = _current_company;
 
		owner = company;
 
	}
 

	
 
	/* do the drill? */
 
@@ -475,7 +489,7 @@ CommandCost CmdBuildBridge(TileIndex end
 

	
 
	if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
 
		Track track = AxisToTrack(direction);
 
		AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, _current_company);
 
		AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, company);
 
		YapfNotifyTrackLayoutChange(tile_start, track);
 
	}
 

	
 
@@ -483,7 +497,7 @@ CommandCost CmdBuildBridge(TileIndex end
 
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
 
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
 
	 */
 
	Company *c = Company::GetIfValid(_current_company);
 
	Company *c = Company::GetIfValid(company);
 
	if (!(flags & DC_QUERY_COST) || (c != NULL && c->is_ai)) {
 
		bridge_len += 2; // begin and end tiles/ramps
 

	
 
@@ -520,6 +534,8 @@ CommandCost CmdBuildBridge(TileIndex end
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyID company = _current_company;
 

	
 
	TransportType transport_type = Extract<TransportType, 8, 2>(p1);
 

	
 
	RailType railtype = INVALID_RAILTYPE;
 
@@ -533,12 +549,24 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
		case TRANSPORT_ROAD:
 
			rts = Extract<RoadTypes, 0, 2>(p1);
 
			if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 
			if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(company, rts)) return CMD_ERROR;
 
			break;
 

	
 
		default: return CMD_ERROR;
 
	}
 

	
 
	if (company == OWNER_DEITY) {
 
		if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
 
		const Town *town = CalcClosestTownFromTile(start_tile);
 

	
 
		company = OWNER_TOWN;
 

	
 
		/* If we are not within a town, we are not owned by the town */
 
		if (town == NULL || DistanceSquare(start_tile, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
 
			company = OWNER_NONE;
 
		}
 
	}
 

	
 
	int start_z;
 
	int end_z;
 
	Slope start_tileh = GetTileSlope(start_tile, &start_z);
 
@@ -640,13 +668,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = Company::GetIfValid(_current_company);
 
		Company *c = Company::GetIfValid(company);
 
		uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
		if (transport_type == TRANSPORT_RAIL) {
 
			if (!IsTunnelTile(start_tile) && c != NULL) c->infrastructure.rail[railtype] += num_pieces;
 
			MakeRailTunnel(start_tile, _current_company, direction,                 railtype);
 
			MakeRailTunnel(end_tile,   _current_company, ReverseDiagDir(direction), railtype);
 
			AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_company);
 
			MakeRailTunnel(start_tile, company, direction,                 railtype);
 
			MakeRailTunnel(end_tile,   company, ReverseDiagDir(direction), railtype);
 
			AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
 
			YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
 
		} else {
 
			if (c != NULL) {
 
@@ -655,10 +683,10 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
					c->infrastructure.road[rt] += num_pieces * 2; // A full diagonal road has two road bits.
 
				}
 
			}
 
			MakeRoadTunnel(start_tile, _current_company, direction,                 rts);
 
			MakeRoadTunnel(end_tile,   _current_company, ReverseDiagDir(direction), rts);
 
			MakeRoadTunnel(start_tile, company, direction,                 rts);
 
			MakeRoadTunnel(end_tile,   company, ReverseDiagDir(direction), rts);
 
		}
 
		DirtyCompanyInfrastructureWindows(_current_company);
 
		DirtyCompanyInfrastructureWindows(company);
 
	}
 

	
 
	return cost;
0 comments (0 inline, 0 general)