FS#1676 - Removing docks converts rivers into canals

Attached to Project: OpenTTD
Opened by frosch (frosch) - Monday, 21 January 2008, 18:03 GMT
Last edited by Peter Nelson (peter1138) - Wednesday, 23 January 2008, 10:02 GMT
Type Bug
Category Core
Status Closed
Assigned To Peter Nelson (peter1138)
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version 0.6.0
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


Docks can be built on rivers, but when they get bulldozed they create a canal tile.

Btw. shipdepots and buoys can't be built on rivers at all.
This task depends upon

Closed by  Peter Nelson (peter1138)
Saturday, 02 February 2008, 09:28 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r12042
Comment by Jean-Francois Claeys (Belugas) - Friday, 01 February 2008, 04:19 GMT
I may have found a way to fix it.
Two problems:
1) the assumption that anything above sea level must be a canal
2) the omission to add river to the has_water condition
Here is the patch i am proposing
Comment by Jean-Francois Claeys (Belugas) - Friday, 01 February 2008, 04:20 GMT
yeah... a not related additionnal line feed for code breathing purpose ;)
Comment by frosch (frosch) - Friday, 01 February 2008, 10:31 GMT
If I am not mistaken, that does also not result in rivers.

Btw. I would prefer a really clean solution here. Looking into openttd.cpp reveals that this is about the fifth time, that canals/sea get converted in savegames :)

I thought about changing the map array in the following way:
- Remove WATER_TILE_RIVER and store rivers with WATER_TILE_CLEAR (like canals and sea).
- Add a WaterClass type in m3 bits 0 to 1 (this position is used for railway and road types in MP_STATION) to differ between sea, canals, and rivers.
- This WaterClass can be used in all water stuff (clear water, depot, dock, buoy) as these bits are free. I.e. also remove the water_owner from shipdepot.
- Preserve WaterClass when building/removing things on water.

That would also allow to draw matching ground sprites under shipdepots, docks and buoys. (Though that would require to store the random bits of canals and rivers also in MP_STATION. m4 would be free, but perhaps it is not the best choice.)
Comment by Peter Nelson (peter1138) - Friday, 01 February 2008, 13:22 GMT
That sounds reasonable to me. Random bits can just return zero for docks, as I doubt it is necessary there.

Any downsides?
Comment by Jean-Francois Claeys (Belugas) - Friday, 01 February 2008, 14:14 GMT
I like the idea too, as it would make the code clearer.
As for downsides, who knows...