Changeset - r12526:698996bced64
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-07-28 18:52:16
rubidium@openttd.org
(svn r16974) -Codechange: do simple station build checks and 'decode' p1/p2 first
1 file changed with 28 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -817,47 +817,57 @@ static void GetStationLayout(byte *layou
 
			layout = CreateMulti(layout, plat_len, 4);
 
			layout = CreateMulti(layout, plat_len, 6);
 
		}
 
	}
 
}
 

	
 
/** Build railroad station
 
 * @param tile_org starting position of station dragging/placement
 
/**
 
 * Build railroad station
 
 * @param tile_org northern most position of station dragging/placement
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0- 3) - railtype (p1 & 0xF)
 
 * - p1 = (bit  0- 3) - railtype
 
 * - p1 = (bit  4)    - orientation (Axis)
 
 * - p1 = (bit  8-15) - number of tracks
 
 * - p1 = (bit 16-23) - platform length
 
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - custom station class
 
 * - p2 = (bit  8-15) - custom station id
 
 * - p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 */
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Unpack parameters */
 
	RailType rt    = (RailType)GB(p1, 0, 4);
 
	Axis axis      = Extract<Axis, 4>(p1);
 
	byte numtracks = GB(p1,  8, 8);
 
	byte plat_len  = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = (StationClassID)GB(p2, 0, 8);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
	/* Does the authority allow this? */
 
	if (!CheckIfAuthorityAllowsNewStation(tile_org, flags)) return CMD_ERROR;
 
	if (!ValParamRailtype((RailType)(p1 & 0xF))) return CMD_ERROR;
 

	
 
	/* unpack parameters */
 
	Axis axis = Extract<Axis, 4>(p1);
 
	uint numtracks = GB(p1,  8, 8);
 
	uint plat_len  = GB(p1, 16, 8);
 
	if (!ValParamRailtype(rt)) return CMD_ERROR;
 

	
 
	/* Check if the given station class is valid */
 
	if ((uint)spec_class >= GetNumStationClasses()) return CMD_ERROR;
 
	if (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
 

	
 
	int w_org, h_org;
 
	if (axis == AXIS_X) {
 
		w_org = plat_len;
 
		h_org = numtracks;
 
	} else {
 
		h_org = plat_len;
 
		w_org = numtracks;
 
	}
 

	
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
@@ -877,26 +887,26 @@ CommandCost CmdBuildRailroadStation(Tile
 

	
 
	Station *st = NULL;
 
	bool check_surrounding = true;
 

	
 
	if (_settings_game.station.adjacent_stations) {
 
		if (est != INVALID_STATION) {
 
			if (HasBit(p1, 24) && est != station_to_join) {
 
			if (adjacent && est != station_to_join) {
 
				/* You can't build an adjacent station over the top of one that
 
				 * already exists. */
 
				return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST);
 
			} else {
 
				/* Extend the current station, and don't check whether it will
 
				 * be near any other stations. */
 
				st = Station::GetIfValid(est);
 
				check_surrounding = (st == NULL);
 
			}
 
		} else {
 
			/* There's no station here. Don't check the tiles surrounding this
 
			 * one if the company wanted to build an adjacent station. */
 
			if (HasBit(p1, 24)) check_surrounding = false;
 
			if (adjacent) check_surrounding = false;
 
		}
 
	}
 

	
 
	if (check_surrounding) {
 
		/* Make sure there are no similar stations around us. */
 
		st = GetStationAround(tile_org, w_org, h_org, est);
 
@@ -937,17 +947,14 @@ CommandCost CmdBuildRailroadStation(Tile
 
			if (Company::IsValidID(_current_company)) {
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
		}
 
	}
 

	
 
	/* Check if the given station class is valid */
 
	if (GB(p2, 0, 8) >= GetNumStationClasses()) return CMD_ERROR;
 

	
 
	/* Check if we can allocate a custom stationspec to this station */
 
	const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 0, 8), GB(p2, 8, 8));
 
	const StationSpec *statspec = GetCustomStationSpec(spec_class, 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 != NULL) {
 
		/* Perform NewStation checks */
 

	
 
@@ -1011,13 +1018,13 @@ CommandCost CmdBuildRailroadStation(Tile
 
					}
 
				}
 

	
 
				/* Remove animation if overbuilding */
 
				DeleteAnimatedTile(tile);
 
				byte old_specindex = IsTileType(tile, MP_STATION) ? GetCustomStationSpecIndex(tile) : 0;
 
				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p1, 0, 4));
 
				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, rt);
 
				/* Free the spec if we overbuild something */
 
				DeallocateSpecFromStation(st, old_specindex);
 

	
 
				SetCustomStationSpecIndex(tile, specindex);
 
				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
 
				SetStationAnimationFrame(tile, 0);
 
@@ -1339,13 +1346,13 @@ static RoadStop **FindRoadStopSpot(bool 
 
 * @param flags operation to perform
 
 * @param p1 entrance direction (DiagDirection)
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 *           bit 1: 0 for normal, 1 for drive-through
 
 *           bit 2..3: the roadtypes
 
 *           bit 5: allow stations directly adjacent to other stations.
 
 *           bit 16..31: station ID to join (INVALID_STATION if build new one)
 
 *           bit 16..31: station ID to join (NEW_STATION if build new one)
 
 */
 
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
 
@@ -1703,13 +1710,13 @@ void UpdateAirportsNoise()
 
/** Place an Airport.
 
 * @param tile tile where airport will be built
 
 * @param flags operation to perform
 
 * @param p1 airport type, @see airport.h
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit     0) - allow airports directly adjacent to other airports.
 
 * - p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool airport_upgrade = true;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
@@ -1957,13 +1964,13 @@ static const byte _dock_w_chk[4] = { 2, 
 
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
 

	
 
/** Build a dock/haven.
 
 * @param tile tile where dock will be built
 
 * @param flags operation to perform
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 bit 16-31: station ID to join (INVALID_STATION if build new one)
 
 * @param p2 bit 16-31: station ID to join (NEW_STATION if build new one)
 
 */
 
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
0 comments (0 inline, 0 general)