Dock on competitor canal
4th version: fixed bug found on the 3rd version
Game Setting for Dock and Lock on Competitor Canal on Permanent Rivers
This is a mix of several patches together tweaked to have better interaction with each other. They are:
- 1) Permanent Rivers and Canal on Rivers (4th version)
- 1.1) Canal on River
- 1.2) Permanent Rivers
- 2) Game Setting for Dock and Lock on Competitor Canal (2nd version)
- 2.1) Dock on Competitor Canal (4th version)
- 2.2) Game Setting for Lock on Competitor Canal
I'd like to have help on making this line more readable in the code.
Code: Select all
MakeStation(t + TileOffsByDiagDir(d), IsWaterTile(t + TileOffsByDiagDir(d)) ? HasTileWaterClass(t + TileOffsByDiagDir(d)) && GetWaterClass(t + TileOffsByDiagDir(d)) == WATER_CLASS_RIVER ? wc == WATER_CLASS_CANAL ? o : GetTileOwner(t + TileOffsByDiagDir(d)) : GetTileOwner(t + TileOffsByDiagDir(d)) : wc == WATER_CLASS_SEA ? OWNER_WATER : o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d), wc);
I know what it's doing, but the line is just too big for me to insert comments explaining. I don't really know what I can do to make it easier.
quick draft explaining what that line is doing:
Draft
if sea:
sea was removed
restore sea, set owner to water
(maintain canal not on river)
if bare land:
self canal was removed
restore canal, set canal to self
(maintain canal not on river)
if river && canal on river:
self canal was removed
restore canal, set canal to self
set canal on river
if river && canal not on river:
(it's a real river)
maintain river, maintain owner
(maintain canal not on river)
if canal && canal not on river:
(it's not our canal)
maintain canal, set canal to its owner
(maintain canal not on river)
if canal && canal on river:
(it's not our canal)
maintain canal, set canal to its owner
(maintain canal on river)
Code: Select all
/**
* Make the given tile a dock tile.
* @param t the tile to make a dock
* @param o the owner of the dock
* @param sid the station to which this tile belongs
* @param d the direction of the dock
* @param wc the type of water on this tile
*/
static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
{
MakeStation(t, o, sid, STATION_DOCK, d);
int t2 = t + TileOffsByDiagDir(d);
MakeStation(t2, // Decide the owner of the water tile placed under a dock.
/* Make the owner of the dock tile the same as the current owner of the
* water tile.
* At this point, the information passed by the previous function has
* been prepared in a way which permits the Owner and the WaterClass to
* be set to their intended values.
*
* A canal tile owned by OWNER_NONE has been made sure to have never
* been demolished during preparation, as that is needed to retrieve
* its respective owner, whenever it finds a river tile.
*
* If a river tile is found, it can mean either the previous function
* demolished own canal and a river was restored, as per the Canal on
* River patch's behaviour, or it is indeed a river tile which, albeit
* being demolished, it is kept, as per the Permanent Rivers patch
* behaviour.
* This is not enough to decide on the owner, but the WaterClass of the
* original tile can be used to indicate if there was originally a canal.
* If it was a canal, it means the canal was ours, and not from another
* owner. If it was not a canal, then it was indeed a river.
*
* If a bare land tile is found at this stage, then it is known that no
* river was ever originally present, but it could have been a canal or
* a sea tile. To figure it out, it resorts to checking the original
* WaterClass of the tile even before the clearance test had happen.
* If it was sea, then it sets the owner to OWNER_WATER. If it was a
* canal then it knows that only own canals could have been demolished
* during the clearance check previously, and also that canals
* owned by OWNER_NONE are not demolished.
*/
IsWaterTile(t2) ?
HasTileWaterClass(t2) && GetWaterClass(t2) == WATER_CLASS_RIVER ?
wc == WATER_CLASS_CANAL ? o
: GetTileOwner(t2)
: GetTileOwner(t2)
: wc == WATER_CLASS_SEA ? OWNER_WATER : o,
sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d), wc);
}
Is this explanation and code split clear enough? How can I improve it?
----------
Canal on River
v2:
- behaviour change: Leveling land with rivers or lakes will not immediately demolish them, they must be demolished first.
- improved documentation description.
Todo:
- better error message "Must demolish river or lake first" (but how?)
- (maybe) store canal on river bit flag on m1 bit 7 for convenience, while switching it's current usage to flag completed industry tiles with m1 bit 4 which is currently free.
- better bit field layout description for water tiles.