src/water_cmd.cpp
changeset 6507 26c45f253d31
parent 6486 4f8af35b11eb
child 6574 e1d1a12faaf7
child 9895 7bd07f43b0e3
equal deleted inserted replaced
6506:b8e2ab2eaeff 6507:26c45f253d31
   275 }
   275 }
   276 
   276 
   277 static int32 ClearTile_Water(TileIndex tile, byte flags)
   277 static int32 ClearTile_Water(TileIndex tile, byte flags)
   278 {
   278 {
   279 	switch (GetWaterTileType(tile)) {
   279 	switch (GetWaterTileType(tile)) {
   280 		case WATER_CLEAR:
   280 		case WATER_TILE_CLEAR:
   281 			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
   281 			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
   282 
   282 
   283 			// Make sure no vehicle is on the tile
   283 			// Make sure no vehicle is on the tile
   284 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   284 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   285 
   285 
   292 			if (GetTileOwner(tile) != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
   292 			if (GetTileOwner(tile) != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
   293 
   293 
   294 			if (flags & DC_EXEC) DoClearSquare(tile);
   294 			if (flags & DC_EXEC) DoClearSquare(tile);
   295 			return _price.clear_water;
   295 			return _price.clear_water;
   296 
   296 
   297 		case WATER_COAST: {
   297 		case WATER_TILE_COAST: {
   298 			Slope slope = GetTileSlope(tile, NULL);
   298 			Slope slope = GetTileSlope(tile, NULL);
   299 
   299 
   300 			// Make sure no vehicle is on the tile
   300 			// Make sure no vehicle is on the tile
   301 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   301 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   302 
   302 
   312 			} else {
   312 			} else {
   313 				return _price.purchase_land;
   313 				return _price.purchase_land;
   314 			}
   314 			}
   315 		}
   315 		}
   316 
   316 
   317 		case WATER_LOCK: {
   317 		case WATER_TILE_LOCK: {
   318 			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
   318 			static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
   319 				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
   319 				{ 0,  0}, {0,  0}, { 0, 0}, {0,  0}, // middle
   320 				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
   320 				{-1,  0}, {0,  1}, { 1, 0}, {0, -1}, // lower
   321 				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
   321 				{ 1,  0}, {0, -1}, {-1, 0}, {0,  1}, // upper
   322 			};
   322 			};
   325 			if (_current_player == OWNER_WATER) return CMD_ERROR;
   325 			if (_current_player == OWNER_WATER) return CMD_ERROR;
   326 			// move to the middle tile..
   326 			// move to the middle tile..
   327 			return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
   327 			return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
   328 		}
   328 		}
   329 
   329 
   330 		case WATER_DEPOT:
   330 		case WATER_TILE_DEPOT:
   331 			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
   331 			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
   332 			return RemoveShipDepot(tile, flags);
   332 			return RemoveShipDepot(tile, flags);
   333 
   333 
   334 		default:
   334 		default:
   335 			NOT_REACHED();
   335 			NOT_REACHED();
   434 }
   434 }
   435 
   435 
   436 static void DrawTile_Water(TileInfo *ti)
   436 static void DrawTile_Water(TileInfo *ti)
   437 {
   437 {
   438 	switch (GetWaterTileType(ti->tile)) {
   438 	switch (GetWaterTileType(ti->tile)) {
   439 		case WATER_CLEAR:
   439 		case WATER_TILE_CLEAR:
   440 			DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
   440 			DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
   441 			if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
   441 			if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
   442 			DrawBridgeMiddle(ti);
   442 			DrawBridgeMiddle(ti);
   443 			break;
   443 			break;
   444 
   444 
   445 		case WATER_COAST:
   445 		case WATER_TILE_COAST:
   446 			assert(!IsSteepSlope(ti->tileh));
   446 			assert(!IsSteepSlope(ti->tileh));
   447 			if (_coast_base != 0) {
   447 			if (_coast_base != 0) {
   448 				DrawGroundSprite(_coast_base + ti->tileh, PAL_NONE);
   448 				DrawGroundSprite(_coast_base + ti->tileh, PAL_NONE);
   449 			} else {
   449 			} else {
   450 				DrawGroundSprite(_water_shore_sprites[ti->tileh], PAL_NONE);
   450 				DrawGroundSprite(_water_shore_sprites[ti->tileh], PAL_NONE);
   451 			}
   451 			}
   452 			DrawBridgeMiddle(ti);
   452 			DrawBridgeMiddle(ti);
   453 			break;
   453 			break;
   454 
   454 
   455 		case WATER_LOCK: {
   455 		case WATER_TILE_LOCK: {
   456 			const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
   456 			const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
   457 			DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
   457 			DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
   458 		} break;
   458 		} break;
   459 
   459 
   460 		case WATER_DEPOT:
   460 		case WATER_TILE_DEPOT:
   461 			DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
   461 			DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
   462 			break;
   462 			break;
   463 	}
   463 	}
   464 }
   464 }
   465 
   465 
   495 }
   495 }
   496 
   496 
   497 static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
   497 static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
   498 {
   498 {
   499 	switch (GetWaterTileType(tile)) {
   499 	switch (GetWaterTileType(tile)) {
   500 		case WATER_CLEAR:
   500 		case WATER_TILE_CLEAR:
   501 			if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
   501 			if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
   502 				td->str = STR_3804_WATER;
   502 				td->str = STR_3804_WATER;
   503 			} else {
   503 			} else {
   504 				td->str = STR_LANDINFO_CANAL;
   504 				td->str = STR_LANDINFO_CANAL;
   505 			}
   505 			}
   506 			break;
   506 			break;
   507 		case WATER_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
   507 		case WATER_TILE_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
   508 		case WATER_LOCK : td->str = STR_LANDINFO_LOCK; break;
   508 		case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break;
   509 		case WATER_DEPOT: td->str = STR_3806_SHIP_DEPOT; break;
   509 		case WATER_TILE_DEPOT: td->str = STR_3806_SHIP_DEPOT; break;
   510 		default: assert(0); break;
   510 		default: assert(0); break;
   511 	}
   511 	}
   512 
   512 
   513 	td->owner = GetTileOwner(tile);
   513 	td->owner = GetTileOwner(tile);
   514 }
   514 }
   703 	TrackBits ts;
   703 	TrackBits ts;
   704 
   704 
   705 	if (mode != TRANSPORT_WATER) return 0;
   705 	if (mode != TRANSPORT_WATER) return 0;
   706 
   706 
   707 	switch (GetWaterTileType(tile)) {
   707 	switch (GetWaterTileType(tile)) {
   708 		case WATER_CLEAR: ts = TRACK_BIT_ALL; break;
   708 		case WATER_TILE_CLEAR: ts = TRACK_BIT_ALL; break;
   709 		case WATER_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
   709 		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
   710 		case WATER_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
   710 		case WATER_TILE_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
   711 		case WATER_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
   711 		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
   712 		default: return 0;
   712 		default: return 0;
   713 	}
   713 	}
   714 	if (TileX(tile) == 0) {
   714 	if (TileX(tile) == 0) {
   715 		// NE border: remove tracks that connects NE tile edge
   715 		// NE border: remove tracks that connects NE tile edge
   716 		ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
   716 		ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
   722 	return ts * 0x101;
   722 	return ts * 0x101;
   723 }
   723 }
   724 
   724 
   725 static void ClickTile_Water(TileIndex tile)
   725 static void ClickTile_Water(TileIndex tile)
   726 {
   726 {
   727 	if (GetWaterTileType(tile) == WATER_DEPOT) {
   727 	if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
   728 		TileIndex tile2 = GetOtherShipDepotTile(tile);
   728 		TileIndex tile2 = GetOtherShipDepotTile(tile);
   729 
   729 
   730 		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_Ship);
   730 		ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_Ship);
   731 	}
   731 	}
   732 }
   732 }