diff options
author | frosch <frosch@openttd.org> | 2015-06-20 13:15:35 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2015-06-20 13:15:35 +0000 |
commit | 9b534b4393c8e2e747143948c424aae08695585c (patch) | |
tree | fff7e8993f795ca80a2887d397e0b0569322239c /src | |
parent | 904688c00a14cadce0c8a651146b305a33d39523 (diff) | |
download | openttd-9b534b4393c8e2e747143948c424aae08695585c.tar.xz |
(svn r27309) -Change [FS#6283]: Auto-complete partial roads when building level-crossings. (adf88)
Diffstat (limited to 'src')
-rw-r--r-- | src/rail_cmd.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 1fcdab073..d44eaa166 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -485,37 +485,38 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u RoadTypes roadtypes = GetRoadTypes(tile); RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD); RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM); - if ((track == TRACK_X && (road | tram) == ROAD_Y) || - (track == TRACK_Y && (road | tram) == ROAD_X)) { - switch (roadtypes) { - default: break; - case ROADTYPES_TRAM: - /* Tram crossings must always have road. */ - if (flags & DC_EXEC) { - SetRoadOwner(tile, ROADTYPE_ROAD, _current_company); - Company *c = Company::GetIfValid(_current_company); - if (c != NULL) { - /* A full diagonal tile has two road bits. */ - c->infrastructure.road[ROADTYPE_ROAD] += 2; - DirtyCompanyInfrastructureWindows(c->index); - } - } - roadtypes |= ROADTYPES_ROAD; - cost.AddCost(2 * _price[PR_BUILD_ROAD]); - break; - - case ROADTYPES_ALL: - if (road != tram) return CMD_ERROR; - break; + if ((track == TRACK_X && ((road | tram) & ROAD_X) == 0) || + (track == TRACK_Y && ((road | tram) & ROAD_Y) == 0)) { + Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD); + Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM); + /* Disallow breaking end-of-line of someone else + * so trams can still reverse on this tile. */ + if (Company::IsValidID(tram_owner) && HasExactlyOneBit(tram)) { + CommandCost ret = CheckOwnership(tram_owner); + if (ret.Failed()) return ret; } + /* Crossings must always have a road... */ + uint num_new_road_pieces = 2 - CountBits(road); + if (road == ROAD_NONE) road_owner = _current_company; + roadtypes |= ROADTYPES_ROAD; + /* ...but tram is not required. */ + uint num_new_tram_pieces = (tram != ROAD_NONE) ? 2 - CountBits(tram) : 0; - road |= tram; + cost.AddCost((num_new_road_pieces + num_new_tram_pieces) * _price[PR_BUILD_ROAD]); if (flags & DC_EXEC) { - MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile)); + MakeRoadCrossing(tile, road_owner, tram_owner, _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile)); UpdateLevelCrossing(tile, false); Company::Get(_current_company)->infrastructure.rail[railtype] += LEVELCROSSING_TRACKBIT_FACTOR; DirtyCompanyInfrastructureWindows(_current_company); + if (num_new_road_pieces > 0 && Company::IsValidID(road_owner)) { + Company::Get(road_owner)->infrastructure.road[ROADTYPE_ROAD] += num_new_road_pieces; + DirtyCompanyInfrastructureWindows(road_owner); + } + if (num_new_tram_pieces > 0 && Company::IsValidID(tram_owner)) { + Company::Get(tram_owner)->infrastructure.road[ROADTYPE_TRAM] += num_new_tram_pieces; + DirtyCompanyInfrastructureWindows(tram_owner); + } } break; } |