src/road_cmd.cpp
changeset 7158 ffb31324aa5e
parent 7157 270bc5b64e08
child 7162 b769c2b45103
equal deleted inserted replaced
7157:270bc5b64e08 7158:ffb31324aa5e
   145 				c |= (RoadBits)((c & 0x3) << 2);
   145 				c |= (RoadBits)((c & 0x3) << 2);
   146 			}
   146 			}
   147 
   147 
   148 			/* limit the bits to delete to the existing bits. */
   148 			/* limit the bits to delete to the existing bits. */
   149 			c &= present;
   149 			c &= present;
   150 			if (c == 0) return CMD_ERROR;
   150 			if (c == ROAD_NONE) return CMD_ERROR;
   151 
   151 
   152 			if (flags & DC_EXEC) {
   152 			if (flags & DC_EXEC) {
   153 				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
   153 				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
   154 
   154 
   155 				present ^= c;
   155 				present ^= c;
   156 				if (present == 0) {
   156 				if (present == ROAD_NONE) {
   157 					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
   157 					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
   158 					if (rts == ROADTYPES_NONE) {
   158 					if (rts == ROADTYPES_NONE) {
   159 						DoClearSquare(tile);
   159 						DoClearSquare(tile);
   160 					} else {
   160 					} else {
       
   161 						SetRoadBits(tile, ROAD_NONE, rt);
   161 						SetRoadTypes(tile, rts);
   162 						SetRoadTypes(tile, rts);
   162 					}
   163 					}
   163 				} else {
   164 				} else {
   164 					SetRoadBits(tile, present, rt);
   165 					SetRoadBits(tile, present, rt);
   165 					MarkTileDirtyByTile(tile);
   166 					MarkTileDirtyByTile(tile);
   297 	switch (GetTileType(tile)) {
   298 	switch (GetTileType(tile)) {
   298 		case MP_STREET:
   299 		case MP_STREET:
   299 			switch (GetRoadTileType(tile)) {
   300 			switch (GetRoadTileType(tile)) {
   300 				case ROAD_TILE_NORMAL:
   301 				case ROAD_TILE_NORMAL:
   301 					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
   302 					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
       
   303 					if (!HASBIT(GetRoadTypes(tile), rt)) break;
   302 
   304 
   303 					existing = GetRoadBits(tile, rt);
   305 					existing = GetRoadBits(tile, rt);
   304 					if ((existing & pieces) == pieces) {
   306 					if ((existing & pieces) == pieces) {
   305 						return_cmd_error(STR_1007_ALREADY_BUILT);
   307 						return_cmd_error(STR_1007_ALREADY_BUILT);
   306 					}
   308 					}
   379 
   381 
   380 	cost += CountRoadBits(pieces) * _price.build_road;
   382 	cost += CountRoadBits(pieces) * _price.build_road;
   381 
   383 
   382 	if (flags & DC_EXEC) {
   384 	if (flags & DC_EXEC) {
   383 		if (IsTileType(tile, MP_STREET)) {
   385 		if (IsTileType(tile, MP_STREET)) {
   384 			if (existing == 0) {
   386 			if (existing == ROAD_NONE) {
   385 				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
   387 				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
   386 				SetRoadOwner(tile, rt, _current_player);
   388 				SetRoadOwner(tile, rt, _current_player);
   387 			}
   389 			}
   388 			SetRoadBits(tile, existing | pieces, rt);
   390 			SetRoadBits(tile, existing | pieces, rt);
   389 		} else {
   391 		} else {
   432  * @param p1 start tile of drag
   434  * @param p1 start tile of drag
   433  * @param p2 various bitstuffed elements
   435  * @param p2 various bitstuffed elements
   434  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
   436  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
   435  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
   437  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
   436  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   438  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   437  * - p2 = (bit 3) - road type
   439  * - p2 = (bit 3 + 4) - road type
   438  */
   440  */
   439 int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   441 int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   440 {
   442 {
   441 	TileIndex start_tile, tile;
   443 	TileIndex start_tile, tile;
   442 	int32 cost, ret;
   444 	int32 cost, ret;
   444 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   446 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   445 
   447 
   446 	if (p1 >= MapSize()) return CMD_ERROR;
   448 	if (p1 >= MapSize()) return CMD_ERROR;
   447 
   449 
   448 	start_tile = p1;
   450 	start_tile = p1;
   449 	RoadType rt = (RoadType)HASBIT(p2, 3);
   451 	RoadType rt = (RoadType)GB(p2, 3, 2);
       
   452 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   450 
   453 
   451 	/* Only drag in X or Y direction dictated by the direction variable */
   454 	/* Only drag in X or Y direction dictated by the direction variable */
   452 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   455 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   453 	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
   456 	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
   454 
   457 
   491  * @param p1 start tile of drag
   494  * @param p1 start tile of drag
   492  * @param p2 various bitstuffed elements
   495  * @param p2 various bitstuffed elements
   493  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
   496  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
   494  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
   497  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
   495  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   498  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   496  * - p2 = (bit 3) - road type
   499  * - p2 = (bit 3 + 4) - road type
   497  */
   500  */
   498 int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   501 int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   499 {
   502 {
   500 	TileIndex start_tile, tile;
   503 	TileIndex start_tile, tile;
   501 	int32 cost, ret;
   504 	int32 cost, ret;
   503 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   506 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   504 
   507 
   505 	if (p1 >= MapSize()) return CMD_ERROR;
   508 	if (p1 >= MapSize()) return CMD_ERROR;
   506 
   509 
   507 	start_tile = p1;
   510 	start_tile = p1;
   508 	RoadType rt = (RoadType)HASBIT(p2, 3);
   511 	RoadType rt = (RoadType)GB(p2, 3, 2);
       
   512 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   509 
   513 
   510 	/* Only drag in X or Y direction dictated by the direction variable */
   514 	/* Only drag in X or Y direction dictated by the direction variable */
   511 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   515 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   512 	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
   516 	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
   513 
   517 
   544 
   548 
   545 /** Build a road depot.
   549 /** Build a road depot.
   546  * @param tile tile where to build the depot
   550  * @param tile tile where to build the depot
   547  * @param flags operation to perform
   551  * @param flags operation to perform
   548  * @param p1 bit 0..1 entrance direction (DiagDirection)
   552  * @param p1 bit 0..1 entrance direction (DiagDirection)
   549  *           bit    2 road type
   553  *           bit 2..3 road type
   550  * @param p2 unused
   554  * @param p2 unused
   551  *
   555  *
   552  * @todo When checking for the tile slope,
   556  * @todo When checking for the tile slope,
   553  * distingush between "Flat land required" and "land sloped in wrong direction"
   557  * distingush between "Flat land required" and "land sloped in wrong direction"
   554  */
   558  */
   559 	Slope tileh;
   563 	Slope tileh;
   560 
   564 
   561 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   565 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   562 
   566 
   563 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   567 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   564 	RoadType rt = (RoadType)HASBIT(p1, 2);
   568 	RoadType rt = (RoadType)GB(p1, 2, 2);
       
   569 
       
   570 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   565 
   571 
   566 	tileh = GetTileSlope(tile, NULL);
   572 	tileh = GetTileSlope(tile, NULL);
   567 	if (tileh != SLOPE_FLAT && (
   573 	if (tileh != SLOPE_FLAT && (
   568 				!_patches.build_on_slopes ||
   574 				!_patches.build_on_slopes ||
   569 				IsSteepSlope(tileh) ||
   575 				IsSteepSlope(tileh) ||