equal
deleted
inserted
replaced
171 } |
171 } |
172 |
172 |
173 return true; |
173 return true; |
174 } |
174 } |
175 |
175 |
176 static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt) |
|
177 { |
|
178 return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt); |
|
179 } |
|
180 |
|
181 |
176 |
182 /** Delete a piece of road. |
177 /** Delete a piece of road. |
183 * @param tile tile where to remove road from |
178 * @param tile tile where to remove road from |
184 * @param flags operation to perform |
179 * @param flags operation to perform |
185 * @param pieces roadbits to remove |
180 * @param pieces roadbits to remove |
193 |
188 |
194 /* true if the roadpiece was always removeable, |
189 /* true if the roadpiece was always removeable, |
195 * false if it was a center piece. Affects town ratings drop */ |
190 * false if it was a center piece. Affects town ratings drop */ |
196 bool edge_road; |
191 bool edge_road; |
197 |
192 |
|
193 RoadTypes rts = GetRoadTypes(tile); |
|
194 /* The tile doesn't have the given road type */ |
|
195 if (!HasBit(rts, rt)) return CMD_ERROR; |
|
196 |
198 Town *t = NULL; |
197 Town *t = NULL; |
199 switch (GetTileType(tile)) { |
198 switch (GetTileType(tile)) { |
200 case MP_ROAD: |
199 case MP_ROAD: |
201 if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile); |
200 if (_game_mode != GM_EDITOR && IsRoadOwner(tile, rt, OWNER_TOWN)) t = GetTownByTile(tile); |
202 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
201 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
203 break; |
202 break; |
204 |
203 |
205 case MP_STATION: |
204 case MP_STATION: |
206 if (!IsDriveThroughStopTile(tile)) return CMD_ERROR; |
205 if (!IsDriveThroughStopTile(tile)) return CMD_ERROR; |
214 |
213 |
215 default: |
214 default: |
216 return CMD_ERROR; |
215 return CMD_ERROR; |
217 } |
216 } |
218 |
217 |
219 RoadTypes rts = GetRoadTypes(tile); |
218 if (!CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rt), &edge_road, rt)) return CMD_ERROR; |
220 /* The tile doesn't have the given road type */ |
|
221 if (!HasBit(rts, rt)) return CMD_ERROR; |
|
222 |
|
223 if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR; |
|
224 |
219 |
225 /* check if you're allowed to remove the street owned by a town |
220 /* check if you're allowed to remove the street owned by a town |
226 * removal allowance depends on difficulty setting */ |
221 * removal allowance depends on difficulty setting */ |
227 if (town_check && !CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
222 if (town_check && !CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
228 |
223 |
499 /* Junctions cannot be one-way */ |
494 /* Junctions cannot be one-way */ |
500 return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
495 return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
501 } |
496 } |
502 if ((existing & pieces) == pieces) { |
497 if ((existing & pieces) == pieces) { |
503 /* We only want to set the (dis)allowed road directions */ |
498 /* We only want to set the (dis)allowed road directions */ |
504 if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) { |
499 if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) { |
505 if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
500 if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
506 |
501 |
507 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
502 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
508 |
503 |
509 /* Ignore half built tiles */ |
504 /* Ignore half built tiles */ |
892 RoadBits b = GetAllRoadBits(tile); |
887 RoadBits b = GetAllRoadBits(tile); |
893 |
888 |
894 /* Clear the road if only one piece is on the tile OR the AI tries |
889 /* Clear the road if only one piece is on the tile OR the AI tries |
895 * to clear town road OR we are not using the DC_AUTO flag */ |
890 * to clear town road OR we are not using the DC_AUTO flag */ |
896 if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || |
891 if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || |
897 ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) || |
892 ((flags & DC_AI_BUILDING) && GetOtherRoadBits(tile, ROADTYPE_ROAD) == ROAD_NONE && IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) || |
898 !(flags & DC_AUTO) |
893 !(flags & DC_AUTO) |
899 ) { |
894 ) { |
900 RoadTypes rts = GetRoadTypes(tile); |
895 RoadTypes rts = GetRoadTypes(tile); |
901 CommandCost ret(EXPENSES_CONSTRUCTION); |
896 CommandCost ret(EXPENSES_CONSTRUCTION); |
902 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
897 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
1547 } |
1542 } |
1548 return; |
1543 return; |
1549 } |
1544 } |
1550 |
1545 |
1551 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
1546 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
1552 /* ROADTYPE_ROAD denotes the tile owner, so update it too */ |
1547 /* Update all roadtypes, no matter if they are present */ |
1553 if (rt != ROADTYPE_ROAD && !HasTileRoadType(tile, rt)) continue; |
|
1554 |
|
1555 if (GetRoadOwner(tile, rt) == old_player) { |
1548 if (GetRoadOwner(tile, rt) == old_player) { |
1556 SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player); |
1549 SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player); |
1557 } |
1550 } |
1558 } |
1551 } |
1559 |
1552 |