本文整理汇总了C++中Waypoint::IsInUse方法的典型用法代码示例。如果您正苦于以下问题:C++ Waypoint::IsInUse方法的具体用法?C++ Waypoint::IsInUse怎么用?C++ Waypoint::IsInUse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Waypoint
的用法示例。
在下文中一共展示了Waypoint::IsInUse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdBuildRailWaypoint
/**
* Convert existing rail to waypoint. Eg build a waypoint station over
* piece of rail
* @param start_tile northern most tile where waypoint will be built
* @param flags type of operation
* @param p1 various bitstuffed elements
* - p1 = (bit 4) - orientation (Axis)
* - p1 = (bit 8-15) - width of waypoint
* - p1 = (bit 16-23) - height of waypoint
* - p1 = (bit 24) - allow waypoints directly adjacent to other waypoints.
* @param p2 various bitstuffed elements
* - p2 = (bit 0- 7) - custom station class
* - p2 = (bit 8-15) - custom station id
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
/* Unpack parameters */
Axis axis = Extract<Axis, 4, 1>(p1);
byte width = GB(p1, 8, 8);
byte height = GB(p1, 16, 8);
bool adjacent = HasBit(p1, 24);
StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
byte spec_index = GB(p2, 8, 8);
StationID station_to_join = GB(p2, 16, 16);
/* Check if the given station class is valid */
if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
/* The number of parts to build */
byte count = axis == AXIS_X ? height : width;
if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
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 || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
StationID est = INVALID_STATION;
/* Check whether the tiles we're building on are valid rail or not. */
TileIndexDiff offset = TileOffsByDiagDir(AxisToDiagDir(OtherAxis(axis)));
for (int i = 0; i < count; i++) {
TileIndex tile = start_tile + i * offset;
CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
if (ret.Failed()) return ret;
}
Waypoint *wp = NULL;
TileArea new_location(TileArea(start_tile, width, height));
CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
if (ret.Failed()) return ret;
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
TileIndex center_tile = start_tile + (count / 2) * offset;
if (wp == NULL && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
if (wp != NULL) {
/* Reuse an existing waypoint. */
if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
/* check if we want to expand an already existing waypoint? */
if (wp->train_station.tile != INVALID_TILE) {
CommandCost ret = CanExpandRailStation(wp, new_location, axis);
if (ret.Failed()) return ret;
}
CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
if (ret.Failed()) return ret;
} else {
/* allocate and initialize new waypoint */
if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
}
if (flags & DC_EXEC) {
if (wp == NULL) {
wp = new Waypoint(start_tile);
} else if (!wp->IsInUse()) {
/* Move existing (recently deleted) waypoint to the new location */
wp->xy = start_tile;
}
wp->owner = GetTileOwner(start_tile);
wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
wp->delete_ctr = 0;
wp->facilities |= FACIL_TRAIN;
wp->build_date = _date;
wp->string_id = STR_SV_STNAME_WAYPOINT;
wp->train_station = new_location;
if (wp->town == NULL) MakeDefaultName(wp);
//.........这里部分代码省略.........