Changeset - r14638:c17bbb7e1736
[Not reviewed]
master
0 5 0
terkhen - 14 years ago 2010-02-24 21:45:23
terkhen@openttd.org
(svn r19227) -Codechange: Reorganization of parameters at CmdBuildRoadStop.
5 files changed with 57 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_road.cpp
Show inline comments
 
@@ -519,26 +519,27 @@ static bool NeighbourHasReachableRoad(::
 

	
 
	uint entrance_dir;
 
	if (drive_through) {
 
		entrance_dir = ::TileY(tile) != ::TileY(front);
 
	} else {
 
		entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
 
	}
 

	
 
	uint p2 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 32;
 
	p2 |= drive_through ? 2 : 0;
 
	p2 |= road_veh_type == ROADVEHTYPE_TRUCK ? 1 : 0;
 
	p2 |= ::RoadTypeToRoadTypes(AIObject::GetRoadType()) << 2;
 
	p2 |= entrance_dir << 6;
 
	p2 |= (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
	return AIObject::DoCommand(tile, entrance_dir, p2, CMD_BUILD_ROAD_STOP);
 
	return AIObject::DoCommand(tile, 0, p2, CMD_BUILD_ROAD_STOP);
 
}
 

	
 
/* static */ bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id)
 
{
 
	return _BuildRoadStationInternal(tile, front, road_veh_type, false, station_id);
 
}
 

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

	
src/command_func.h
Show inline comments
 
@@ -114,24 +114,25 @@ CommandCallback CcTerraform;
 
CommandCallback CcGiveMoney;
 

	
 
/* rail_gui.cpp */
 
CommandCallback CcPlaySound1E;
 
CommandCallback CcRailDepot;
 
CommandCallback CcStation;
 
CommandCallback CcBuildRailTunnel;
 

	
 
/* road_gui.cpp */
 
CommandCallback CcPlaySound1D;
 
CommandCallback CcBuildRoadTunnel;
 
CommandCallback CcRoadDepot;
 
CommandCallback CcRoadStop;
 

	
 
/* train_gui.cpp */
 
CommandCallback CcBuildWagon;
 

	
 
/* town_gui.cpp */
 
CommandCallback CcFoundTown;
 
CommandCallback CcFoundRandomTown;
 

	
 
/* vehicle_gui.cpp */
 
CommandCallback CcBuildPrimaryVehicle;
 

	
 
#endif /* COMMAND_FUNC_H */
src/network/network_command.cpp
Show inline comments
 
@@ -38,24 +38,25 @@ static CommandCallback * const _callback
 
	/* 0x0F */ CcPlaySound1E,
 
	/* 0x10 */ CcStation,
 
	/* 0x11 */ CcTerraform,
 
#ifdef ENABLE_AI
 
	/* 0x12 */ CcAI,
 
#else
 
	/* 0x12 */ NULL,
 
#endif /* ENABLE_AI */
 
	/* 0x13 */ CcCloneVehicle,
 
	/* 0x14 */ CcGiveMoney,
 
	/* 0x15 */ CcCreateGroup,
 
	/* 0x16 */ CcFoundRandomTown,
 
	/* 0x17 */ CcRoadStop,
 
};
 

	
 
/** Local queue of packets */
 
static CommandPacket *_local_command_queue = NULL;
 

	
 
/**
 
 * Add a command to the local or client socket command queue,
 
 * based on the socket.
 
 * @param cp the command packet to add
 
 * @param cs the socket to send to (NULL = locally)
 
 */
 
void NetworkAddCommandQueue(CommandPacket cp, NetworkClientSocket *cs)
src/road_gui.cpp
Show inline comments
 
@@ -187,43 +187,67 @@ static void BuildRoadOutsideStation(Tile
 
		}
 
	}
 
}
 

	
 
void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	BuildRoadOutsideStation(tile, dir);
 
	/* For a drive-through road stop build connecting road for other entrance */
 
	if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 
}
 

	
 
static void PlaceRoad_Depot(TileIndex tile)
 
{
 
	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CMD_BUILD_ROAD_DEPOT | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot), CcRoadDepot);
 
}
 

	
 
/** Command callback for building road stops.
 
 * @param result Result of the build road stop command.
 
 * @param tile Tile to build the stop at.
 
 * @param p1 Unused.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2..3: The roadtypes.
 
 *           bit 5: Allow stations directly adjacent to other stations.
 
 *           bit 6..7: Entrance direction (#DiagDirection).
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @see CmdBuildRoadStop
 
 */
 
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p2, 6, 2);
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	BuildRoadOutsideStation(tile, dir);
 
	/* For a drive-through road stop build connecting road for other entrance. */
 
	if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 
}
 

	
 
static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
 
{
 
	uint32 p1 = _road_station_picker_orientation;
 
	uint8 ddir = _road_station_picker_orientation;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	if (p1 >= DIAGDIR_END) {
 
		SetBit(p2, 1); // It's a drive-through stop
 
		p1 -= DIAGDIR_END; // Adjust picker result to actual direction
 
	if (ddir >= DIAGDIR_END) {
 
		SetBit(p2, 1); // It's a drive-through stop.
 
		ddir -= DIAGDIR_END; // Adjust picker result to actual direction.
 
	}
 
	CommandContainer cmdcont = { tile, p1, p2, cmd, CcRoadDepot, "" };
 
	p2 |= ddir << 6; // Set the DiagDirecion into p2 bits 6 and 7.
 

	
 
	CommandContainer cmdcont = { tile, 0, p2, cmd, CcRoadStop, "" };
 
	ShowSelectStationIfNeeded(cmdcont, TileArea(tile, 1, 1));
 
}
 

	
 
static void PlaceRoad_BusStation(TileIndex tile)
 
{
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, 0, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
 
	} else {
 
		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS]));
 
	}
 
}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1577,66 +1577,69 @@ static RoadStop **FindRoadStopSpot(bool 
 

	
 
	if (*primary_stop == NULL) {
 
		/* we have no roadstop of the type yet, so write a "primary stop" */
 
		return primary_stop;
 
	} else {
 
		/* there are stops already, so append to the end of the list */
 
		RoadStop *stop = *primary_stop;
 
		while (stop->next != NULL) stop = stop->next;
 
		return &stop->next;
 
	}
 
}
 

	
 
/** Build a bus or truck stop
 
 * @param tile tile to build the stop at
 
 * @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 (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
/** Build a bus or truck stop.
 
 * @param tile Tile to build the stop at.
 
 * @param flags Operation to perform.
 
 * @param p1 Unused.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2..3: The roadtypes.
 
 *           bit 5: Allow stations directly adjacent to other stations.
 
 *           bit 6..7: Entrance direction (DiagDirection).
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @param text Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
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);
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 2);
 
	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);
 
	Owner tram_owner = _current_company;
 
	Owner road_owner = _current_company;
 

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

	
 
	if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 

	
 
	/* Trams only have drive through stops */
 
	if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
 

	
 
	/* Saveguard the parameters */
 
	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
 
	/* If it is a drive-through stop check for valid axis */
 
	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
 
	DiagDirection ddir = (DiagDirection)GB(p2, 6, 2);
 

	
 
	/* Safeguard the parameters. */
 
	if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
 
	/* If it is a drive-through stop, check for valid axis. */
 
	if (is_drive_through && !IsValidAxis((Axis)ddir)) return CMD_ERROR;
 
	/* Road bits in the wrong direction */
 
	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
 
	if (build_over_road && (GetAllRoadBits(tile) & (DiagDirToAxis(ddir) == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
 

	
 
	if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
 

	
 
	CommandCost cost = CheckFlatLandRoadStop(tile, flags, is_drive_through ? 5 << p1 : 1 << p1, build_over_road, rts);
 
	CommandCost cost = CheckFlatLandRoadStop(tile, flags, is_drive_through ? 5 << ddir : 1 << ddir, build_over_road, rts);
 
	if (cost.Failed()) return cost;
 

	
 
	Station *st = NULL;
 
	CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 5), TileArea(tile, 1, 1), &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	/* give us a road stop in the list, and check if something went wrong */
 
	if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
 

	
 
@@ -1674,28 +1677,28 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
			st->truck_station.Add(tile);
 
		} else {
 
			st->bus_station.Add(tile);
 
		}
 

	
 
		/* initialize an empty station */
 
		st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
 

	
 
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 

	
 
		RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 
		if (is_drive_through) {
 
			MakeDriveThroughRoadStop(tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts, (Axis)p1);
 
			MakeDriveThroughRoadStop(tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts, DiagDirToAxis(ddir));
 
			road_stop->MakeDriveThrough();
 
		} else {
 
			MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1);
 
			MakeRoadStop(tile, st->owner, st->index, rs_type, rts, ddir);
 
		}
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
 
	}
 
	return cost;
 
}
 

	
0 comments (0 inline, 0 general)