Feature: Orientation of rail and road depots can be changed (#9642)

This commit is contained in:
Kuhnovic
2023-07-01 14:11:31 +02:00
committed by GitHub
parent c3fbe7bea8
commit 6169e7f4bc
6 changed files with 134 additions and 59 deletions

View File

@@ -989,24 +989,44 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
}
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
if (cost.Failed()) return cost;
/* Allow the user to rotate the depot instead of having to destroy it and build it again */
bool rotate_existing_depot = false;
if (IsRailDepotTile(tile) && railtype == GetRailType(tile)) {
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (dir == GetRailDepotDirection(tile)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
rotate_existing_depot = true;
}
if (!rotate_existing_depot) {
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
if (cost.Failed()) return cost;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
}
if (flags & DC_EXEC) {
Depot *d = new Depot(tile);
d->build_date = TimerGameCalendar::date;
if (rotate_existing_depot) {
SetRailDepotExitDirection(tile, dir);
} else {
Depot *d = new Depot(tile);
d->build_date = TimerGameCalendar::date;
MakeRailDepot(tile, _current_company, d->index, dir, railtype);
MakeDefaultName(d);
Company::Get(_current_company)->infrastructure.rail[railtype]++;
DirtyCompanyInfrastructureWindows(_current_company);
}
MakeRailDepot(tile, _current_company, d->index, dir, railtype);
MarkTileDirtyByTile(tile);
MakeDefaultName(d);
Company::Get(_current_company)->infrastructure.rail[railtype]++;
DirtyCompanyInfrastructureWindows(_current_company);
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
}

View File

@@ -530,19 +530,37 @@ static inline void MakeRailNormal(Tile t, Owner o, TrackBits b, RailType r)
t.m8() = r;
}
static inline void MakeRailDepot(Tile t, Owner o, DepotID did, DiagDirection d, RailType r)
/**
* Sets the exit direction of a rail depot.
* @param tile Tile of the depot.
* @param dir Direction of the depot exit.
*/
static inline void SetRailDepotExitDirection(Tile tile, DiagDirection dir)
{
SetTileType(t, MP_RAILWAY);
SetTileOwner(t, o);
SetDockingTile(t, false);
t.m2() = did;
t.m3() = 0;
t.m4() = 0;
t.m5() = RAIL_TILE_DEPOT << 6 | d;
SB(t.m6(), 2, 4, 0);
t.m7() = 0;
t.m8() = r;
assert(IsRailDepotTile(tile));
SB(tile.m5(), 0, 2, dir);
}
/**
* Make a rail depot.
* @param tile Tile to make a depot on.
* @param owner New owner of the depot.
* @param depot_id New depot ID.
* @param dir Direction of the depot exit.
* @param rail_type Rail type of the depot.
*/
static inline void MakeRailDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirection dir, RailType rail_type)
{
SetTileType(tile, MP_RAILWAY);
SetTileOwner(tile, owner);
SetDockingTile(tile, false);
tile.m2() = depot_id;
tile.m3() = 0;
tile.m4() = 0;
tile.m5() = RAIL_TILE_DEPOT << 6 | dir;
SB(tile.m6(), 2, 4, 0);
tile.m7() = 0;
tile.m8() = rail_type;
}
#endif /* RAIL_MAP_H */

View File

@@ -1163,24 +1163,46 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt,
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
}
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
if (cost.Failed()) return cost;
/* Allow the user to rotate the depot instead of having to destroy it and build it again */
bool rotate_existing_depot = false;
if (IsRoadDepotTile(tile) && (HasRoadTypeTram(tile) ? rt == GetRoadTypeTram(tile) : rt == GetRoadTypeRoad(tile)))
{
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (dir == GetRoadDepotDirection(tile)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
rotate_existing_depot = true;
}
if (!rotate_existing_depot) {
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
if (cost.Failed()) return cost;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
}
if (flags & DC_EXEC) {
Depot *dep = new Depot(tile);
dep->build_date = TimerGameCalendar::date;
if (rotate_existing_depot) {
SetRoadDepotExitDirection(tile, dir);
} else {
Depot *dep = new Depot(tile);
dep->build_date = TimerGameCalendar::date;
MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
MakeDefaultName(dep);
}
MarkTileDirtyByTile(tile);
/* A road depot has two road bits. */
UpdateCompanyRoadInfrastructure(rt, _current_company, ROAD_DEPOT_TRACKBIT_FACTOR);
MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
MarkTileDirtyByTile(tile);
MakeDefaultName(dep);
}
cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
return cost;
}

View File

@@ -673,26 +673,37 @@ static inline void MakeRoadCrossing(Tile t, Owner road, Owner tram, Owner rail,
}
/**
* Make a road depot.
* @param t Tile to make a level crossing.
* @param owner New owner of the depot.
* @param did New depot ID.
* @param dir Direction of the depot exit.*
* @param rt Road type of the depot.
* Sets the exit direction of a road depot.
* @param tile Tile of the depot.
* @param dir Direction of the depot exit.
*/
static inline void MakeRoadDepot(Tile t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
static inline void SetRoadDepotExitDirection(Tile tile, DiagDirection dir)
{
SetTileType(t, MP_ROAD);
SetTileOwner(t, owner);
t.m2() = did;
t.m3() = 0;
t.m4() = INVALID_ROADTYPE;
t.m5() = ROAD_TILE_DEPOT << 6 | dir;
SB(t.m6(), 2, 4, 0);
t.m7() = owner;
t.m8() = INVALID_ROADTYPE << 6;
SetRoadType(t, GetRoadTramType(rt), rt);
SetRoadOwner(t, RTT_TRAM, owner);
assert(IsRoadDepotTile(tile));
SB(tile.m5(), 0, 2, dir);
}
/**
* Make a road depot.
* @param tile Tile to make a depot on.
* @param owner New owner of the depot.
* @param depot_id New depot ID.
* @param dir Direction of the depot exit.
* @param rail_type Road type of the depot.
*/
static inline void MakeRoadDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirection dir, RoadType rail_type)
{
SetTileType(tile, MP_ROAD);
SetTileOwner(tile, owner);
tile.m2() = depot_id;
tile.m3() = 0;
tile.m4() = INVALID_ROADTYPE;
tile.m5() = ROAD_TILE_DEPOT << 6 | dir;
SB(tile.m6(), 2, 4, 0);
tile.m7() = owner;
tile.m8() = INVALID_ROADTYPE << 6;
SetRoadType(tile, GetRoadTramType(rail_type), rail_type);
SetRoadOwner(tile, RTT_TRAM, owner);
}
#endif /* ROAD_MAP_H */