83 return CheckAllowRemoveRoad(tile, remove, IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile), edge_road); |
84 return CheckAllowRemoveRoad(tile, remove, IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile), edge_road); |
84 } |
85 } |
85 |
86 |
86 /** Delete a piece of road. |
87 /** Delete a piece of road. |
87 * @param tile tile where to remove road from |
88 * @param tile tile where to remove road from |
88 * @param p1 road piece flags |
89 * @param p1 bit 0..3 road pieces to remove (RoadBits) |
89 * @param p2 unused |
90 * @param p2 unused |
90 */ |
91 */ |
91 int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
92 int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
92 { |
93 { |
93 // cost for removing inner/edge -roads |
94 // cost for removing inner/edge -roads |
96 Owner owner; |
97 Owner owner; |
97 Town *t; |
98 Town *t; |
98 /* true if the roadpiece was always removeable, |
99 /* true if the roadpiece was always removeable, |
99 * false if it was a center piece. Affects town ratings drop */ |
100 * false if it was a center piece. Affects town ratings drop */ |
100 bool edge_road; |
101 bool edge_road; |
101 RoadBits pieces; |
|
102 |
102 |
103 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
103 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
104 |
|
105 /* Road pieces are max 4 bitset values (NE, NW, SE, SW) */ |
|
106 if (p1 >> 4) return CMD_ERROR; |
|
107 pieces = (RoadBits)p1; |
|
108 |
104 |
109 if (!IsTileType(tile, MP_STREET)) return CMD_ERROR; |
105 if (!IsTileType(tile, MP_STREET)) return CMD_ERROR; |
110 |
106 |
111 owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); |
107 owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); |
112 |
108 |
113 if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) { |
109 if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) { |
114 t = GetTownByTile(tile); |
110 t = GetTownByTile(tile); |
115 } else { |
111 } else { |
116 t = NULL; |
112 t = NULL; |
117 } |
113 } |
|
114 |
|
115 RoadBits pieces = Extract<RoadBits, 0>(p1); |
118 |
116 |
119 if (!CheckAllowRemoveRoad(tile, pieces, &edge_road)) return CMD_ERROR; |
117 if (!CheckAllowRemoveRoad(tile, pieces, &edge_road)) return CMD_ERROR; |
120 |
118 |
121 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
119 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
122 |
120 |
247 return CMD_ERROR; |
245 return CMD_ERROR; |
248 } |
246 } |
249 |
247 |
250 /** Build a piece of road. |
248 /** Build a piece of road. |
251 * @param tile tile where to build road |
249 * @param tile tile where to build road |
252 * @param p1 road piece flags |
250 * @param p1 bit 0..3 road pieces to build (RoadBits) |
253 * @param p2 the town that is building the road (0 if not applicable) |
251 * @param p2 the town that is building the road (0 if not applicable) |
254 */ |
252 */ |
255 int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
253 int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
256 { |
254 { |
257 int32 cost = 0; |
255 int32 cost = 0; |
258 int32 ret; |
256 int32 ret; |
259 RoadBits existing = ROAD_NONE; |
257 RoadBits existing = ROAD_NONE; |
260 RoadBits pieces; |
|
261 Slope tileh; |
258 Slope tileh; |
262 |
259 |
263 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
260 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
264 |
261 |
265 /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero |
262 /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero |
266 * if a non-player is building the road */ |
263 * if a non-player is building the road */ |
267 if ((p1 >> 4) || (IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR; |
264 if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR; |
268 pieces = (RoadBits)p1; |
265 |
|
266 RoadBits pieces = Extract<RoadBits, 0>(p1); |
269 |
267 |
270 tileh = GetTileSlope(tile, NULL); |
268 tileh = GetTileSlope(tile, NULL); |
271 |
269 |
272 switch (GetTileType(tile)) { |
270 switch (GetTileType(tile)) { |
273 case MP_STREET: |
271 case MP_STREET: |
500 return (cost == 0) ? CMD_ERROR : cost; |
498 return (cost == 0) ? CMD_ERROR : cost; |
501 } |
499 } |
502 |
500 |
503 /** Build a road depot. |
501 /** Build a road depot. |
504 * @param tile tile where to build the depot |
502 * @param tile tile where to build the depot |
505 * @param p1 entrance direction (DiagDirection) |
503 * @param p1 bit 0..1 entrance direction (DiagDirection) |
506 * @param p2 unused |
504 * @param p2 unused |
507 * |
505 * |
508 * @todo When checking for the tile slope, |
506 * @todo When checking for the tile slope, |
509 * distingush between "Flat land required" and "land sloped in wrong direction" |
507 * distingush between "Flat land required" and "land sloped in wrong direction" |
510 */ |
508 */ |
514 Depot *dep; |
512 Depot *dep; |
515 Slope tileh; |
513 Slope tileh; |
516 |
514 |
517 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
515 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
518 |
516 |
519 if (p1 > 3) return CMD_ERROR; // check direction |
517 DiagDirection dir = Extract<DiagDirection, 0>(p1); |
520 |
518 |
521 tileh = GetTileSlope(tile, NULL); |
519 tileh = GetTileSlope(tile, NULL); |
522 if (tileh != SLOPE_FLAT && ( |
520 if (tileh != SLOPE_FLAT && ( |
523 !_patches.build_on_slopes || |
521 !_patches.build_on_slopes || |
524 IsSteepSlope(tileh) || |
522 IsSteepSlope(tileh) || |
525 !CanBuildDepotByTileh(p1, tileh) |
523 !CanBuildDepotByTileh(dir, tileh) |
526 )) { |
524 )) { |
527 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
525 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
528 } |
526 } |
529 |
527 |
530 cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
528 cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
537 |
535 |
538 if (flags & DC_EXEC) { |
536 if (flags & DC_EXEC) { |
539 dep->xy = tile; |
537 dep->xy = tile; |
540 dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
538 dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
541 |
539 |
542 MakeRoadDepot(tile, _current_player, (DiagDirection)p1); |
540 MakeRoadDepot(tile, _current_player, dir); |
543 MarkTileDirtyByTile(tile); |
541 MarkTileDirtyByTile(tile); |
544 } |
542 } |
545 return cost + _price.build_road_depot; |
543 return cost + _price.build_road_depot; |
546 } |
544 } |
547 |
545 |