water_cmd.c
changeset 1632 c4ae19bfebf7
parent 1605 c4630be67467
child 1752 cdbfb2f23e72
equal deleted inserted replaced
1631:b54ca823e323 1632:c4ae19bfebf7
   177 		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   177 		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   178 }
   178 }
   179 
   179 
   180 int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   180 int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   181 {
   181 {
   182 	uint tile = TILE_FROM_XY(x,y);
   182 	int32 ret, cost;
   183 	int32 ret;
   183 	int size_x, size_y;
   184 	uint th;
   184 	int sx = TileX((TileIndex)p1);
   185 	uint endtile = (uint)p1;
   185 	int sy = TileY((TileIndex)p1);
   186 	int delta;
   186 	x >>= 4; y >>= 4;
   187 	int32 cost;
   187 
   188 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   188 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   189 
   189 
   190 	// move in which direction?
   190 	if (x < sx) intswap(x, sx);
   191 	delta = (TileX(tile) == TileX(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0);
   191 	if (y < sy) intswap(y, sy);
   192 	if (endtile < tile) delta = -delta;
   192 	size_x = (x - sx) + 1;
       
   193 	size_y = (y - sy) + 1;
   193 
   194 
   194 	cost = 0;
   195 	cost = 0;
   195 	for(;;) {
   196 	BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
   196 		ret = 0;
   197 		ret = 0;
   197 		th = GetTileSlope(tile, NULL);
   198 		if (GetTileSlope(tile, NULL) != 0)
   198 		if(th!=0)
       
   199 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   199 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   200 
   200 
   201 			// can't make water of water!
   201 			// can't make water of water!
   202 			if (IsTileType(tile, MP_WATER)) {
   202 			if (IsTileType(tile, MP_WATER)) {
   203 				_error_message = STR_1007_ALREADY_BUILT;
   203 				_error_message = STR_1007_ALREADY_BUILT;
   204 			} else {
   204 			} else {
   205 
       
   206 				/* is middle piece of a bridge? */
   205 				/* is middle piece of a bridge? */
   207 				if (IsTileType(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */
   206 				if (IsTileType(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */
   208 					if(_map5[tile] & 0x20) { // transport route under bridge
   207 					if (_map5[tile] & 0x20) { // transport route under bridge
   209 						_error_message = STR_5800_OBJECT_IN_THE_WAY;
   208 						_error_message = STR_5800_OBJECT_IN_THE_WAY;
   210 						ret = CMD_ERROR;
   209 						ret = CMD_ERROR;
   211 					}
   210 					}
   212 					else if (_map5[tile] & 0x18) { // already water under bridge
   211 					else if (_map5[tile] & 0x18) { // already water under bridge
   213 						_error_message = STR_1007_ALREADY_BUILT;
   212 						_error_message = STR_1007_ALREADY_BUILT;
   214 						ret = CMD_ERROR;
   213 						ret = CMD_ERROR;
   215 					}
   214 					}
   216 
       
   217 				/* no bridge? then try to clear it. */
   215 				/* no bridge? then try to clear it. */
   218 				} else  {
   216 				} else
   219 					ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   217 					ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   220 				}
   218 
   221 				if (ret == CMD_ERROR) return ret;
   219 				if (ret == CMD_ERROR) return ret;
   222 				cost += ret;
   220 				cost += ret;
   223 
   221 
   224 				/* execute modifications */
   222 				/* execute modifications */
   225 				if (flags & DC_EXEC) {
   223 				if (flags & DC_EXEC) {
   233 					MarkTilesAroundDirty(tile);
   231 					MarkTilesAroundDirty(tile);
   234 				}
   232 				}
   235 
   233 
   236 				cost += _price.clear_water;
   234 				cost += _price.clear_water;
   237 			}
   235 			}
   238 		if (tile == endtile)
   236 	} END_TILE_LOOP(tile, size_x, size_y, 0);
   239 			break;
   237 
   240 		tile += delta;
   238 	return (cost == 0) ? CMD_ERROR : cost;
   241 	}
       
   242 	if (cost == 0) return CMD_ERROR;
       
   243 
       
   244 	return cost;
       
   245 }
   239 }
   246 
   240 
   247 static int32 ClearTile_Water(uint tile, byte flags) {
   241 static int32 ClearTile_Water(uint tile, byte flags) {
   248 	byte m5 = _map5[tile];
   242 	byte m5 = _map5[tile];
   249 	uint slope;
   243 	uint slope;