Changeset - r19685:8ccaeb42d4b3
[Not reviewed]
master
0 2 0
zuu - 12 years ago 2012-10-25 19:25:31
zuu@openttd.org
(svn r24628) -Fix: Document and enforce precondition start != end for ScriptRoad::RemoveRoad and ScriptRoad::RemoveRoadFull
2 files changed with 4 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_road.cpp
Show inline comments
 
@@ -528,35 +528,37 @@ static bool NeighbourHasReachableRoad(::
 
{
 
	return _BuildRoadStationInternal(tile, front, road_veh_type, false, station_id);
 
}
 

	
 
/* static */ bool ScriptRoad::BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id)
 
{
 
	return _BuildRoadStationInternal(tile, front, road_veh_type, true, station_id);
 
}
 

	
 
/* static */ bool ScriptRoad::RemoveRoad(TileIndex start, TileIndex end)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, start != end);
 
	EnforcePrecondition(false, ::IsValidTile(start));
 
	EnforcePrecondition(false, ::IsValidTile(end));
 
	EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
 
	EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
 

	
 
	return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
 
}
 

	
 
/* static */ bool ScriptRoad::RemoveRoadFull(TileIndex start, TileIndex end)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, start != end);
 
	EnforcePrecondition(false, ::IsValidTile(start));
 
	EnforcePrecondition(false, ::IsValidTile(end));
 
	EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
 
	EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
 

	
 
	return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
 
}
 

	
 
/* static */ bool ScriptRoad::RemoveRoadDepot(TileIndex tile)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, ::IsValidTile(tile));
src/script/api/script_road.hpp
Show inline comments
 
@@ -409,43 +409,45 @@ public:
 
	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
 
	 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
 
	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS
 
	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN
 
	 * @return Whether the station has been/can be build or not.
 
	 */
 
	static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
 

	
 
	/**
 
	 * Removes a road from the center of tile start to the center of tile end.
 
	 * @param start The start tile of the road.
 
	 * @param end The end tile of the road.
 
	 * @pre 'start' is not equal to 'end'.
 
	 * @pre ScriptMap::IsValidTile(start).
 
	 * @pre ScriptMap::IsValidTile(end).
 
	 * @pre 'start' and 'end' are in a straight line, i.e.
 
	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
 
	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
 
	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
 
	 * @game @pre Valid ScriptCompanyMode active in scope.
 
	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
 
	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
 
	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
 
	 * @return Whether the road has been/can be removed or not.
 
	 */
 
	static bool RemoveRoad(TileIndex start, TileIndex end);
 

	
 
	/**
 
	 * Removes a road from the edge of tile start to the edge of tile end (both
 
	 *  included).
 
	 * @param start The start tile of the road.
 
	 * @param end The end tile of the road.
 
	 * @pre 'start' is not equal to 'end'.
 
	 * @pre ScriptMap::IsValidTile(start).
 
	 * @pre ScriptMap::IsValidTile(end).
 
	 * @pre 'start' and 'end' are in a straight line, i.e.
 
	 *  ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
 
	 *  ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
 
	 * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
 
	 * @game @pre Valid ScriptCompanyMode active in scope.
 
	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
 
	 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
 
	 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS
 
	 * @return Whether the road has been/can be removed or not.
 
	 */
0 comments (0 inline, 0 general)