terraforming rivers testing patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

terraforming rivers testing patch

Post by xarick »

terraforming rivers testing v2 r27528.patch
(1.95 KiB) Downloaded 92 times

Code: Select all

Index: src/water_cmd.cpp
===================================================================
--- src/water_cmd.cpp	(revision 27528)
+++ src/water_cmd.cpp	(working copy)
@@ -39,6 +39,7 @@
 #include "company_base.h"
 #include "company_gui.h"
 #include "newgrf_generic.h"
+#include "cheat_type.h"
 
 #include "table/strings.h"
 
@@ -409,7 +410,7 @@
 		CommandCost ret;
 
 		Slope slope = GetTileSlope(tile);
-		if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
+		if (slope != SLOPE_FLAT && wc != WATER_CLASS_RIVER) {
 			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 		}
 
@@ -1233,6 +1234,7 @@
 
 static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 {
+	static const byte clear_tracks[] = {63, 32, 4, 0, 16, 0, 0, 8, 8, 0, 0, 16, 0, 4, 32, 63};
 	static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
 
 	TrackBits ts;
@@ -1240,7 +1242,7 @@
 	if (mode != TRANSPORT_WATER) return 0;
 
 	switch (GetWaterTileType(tile)) {
-		case WATER_TILE_CLEAR: ts = IsTileFlat(tile) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
+		case WATER_TILE_CLEAR: ts = IsTileFlat(tile) ? TRACK_BIT_ALL : (TrackBits)clear_tracks[GetTileSlope(tile) & 0xF]; break;
 		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile) & 0xF]; break;
 		case WATER_TILE_LOCK:  ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
 		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
@@ -1312,6 +1314,10 @@
 	/* Canals can't be terraformed */
 	if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
 
+	if (IsWaterTile(tile) && IsRiver(tile)) {
+		if (z_new < 1 && _game_mode == GM_NORMAL && !_cheats.magic_bulldozer.value) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
+		return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
+	}
 	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 }
 
https://onedrive.live.com/redir?resid=2 ... ideo%2cm4v
cmtgwgg[1].png
cmtgwgg[1].png (99.71 KiB) Viewed 2859 times
start these ships.sav
(7.29 KiB) Downloaded 75 times
To do:

- missing river sprites for these slopes (except those that are tagged 'not missing'):
(0) SLOPE_FLAT - not missing
(1) SLOPE_W
(2) SLOPE_S
(4) SLOPE_E
(8) SLOPE_N

(9) SLOPE_NW - not missing
(3) SLOPE_SW - not missing
(6) SLOPE_SE - not missing
(12) SLOPE_NE - not missing
(5) SLOPE_EW
(10) SLOPE_NS

(11) SLOPE_NWS
(7) SLOPE_WSE
(14) SLOPE_SEN
(13) SLOPE_ENW

(27) SLOPE_STEEP_W
(23) SLOPE_STEEP_S
(30) SLOPE_STEEP_E
(29) SLOPE_STEEP_N
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: terraforming rivers testing patch

Post by xarick »

[20:58] <supermop> Samu: if you look at the way ogfx river banks are drawn here, maybe there is a way to just composite what you need in code? http://dev.openttdcoop.org/projects/ogf ... e.gimp.png
Formerly known as Samu
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: terraforming rivers testing patch

Post by supermop »

Here is a test png with 'rapids' for the south facing slopes. There are two options each for the steep and both non-steep slopes. These are made by recombining parts of the ogfx+ rapids found here: http://dev.openttdcoop.org/projects/ogf ... rapids.png

OpenGFX+ has 16 variations of rapids for each of the 4 regular slopes, so if there is a way to slice up and recombine those sprites in code, for the 4 quadrants of each tile, you could maybe have 16^4 semi-random variations for each sprite. Otherwise, we could just make 2-4 variants for each slope manually in Photoshop.

You can overlay the various riverbank sprites over these based on neighboring tiles. I just need to make new diagonal water half-tiles and corresponding river banks for the cases when ariver runs along the edge of a slope instead of down the slope.

I think canals should use foundations rather than complex slope sprites.

Best,
South Slopes.png
South Slopes.png (6.58 KiB) Viewed 2764 times
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: terraforming rivers testing patch

Post by xarick »

Thanks. Now I'm trying to learn what to do next. I suppose I need to edit a .nfo file, namely this one:
https://git.openttd.org/?p=branches/1.6 ... 11;hb=HEAD

From what I can tell, each block in that .nfo represents a variant, and each line for each variant represents a different slope.

(6) SLOPE_SE / (12) SLOPE_NE / (3) SLOPE_SW / (9) SLOPE_NW
Image

The variants are the rows in the image. The columns are each of the slopes.
Formerly known as Samu
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: terraforming rivers testing patch

Post by supermop »

Here are manually composited slopes for North, east, and west flowing rapids. Only one variant for each so far. Again these are composited from OGFX+ sprites so they have same license, gpl2.
North East and West  Slopes.png
North East and West Slopes.png (7.04 KiB) Viewed 2658 times
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: terraforming rivers testing patch

Post by wallyweb »

supermop wrote:I just need to make new diagonal water half-tiles and corresponding river banks for the cases when ariver runs along the edge of a slope instead of down the slope.
I've been looking for a way to do this for a few years now. These tiles exist at sea level but for some unknown (to me) reason, they do not exist for rivers. I really hope the two of you can make this work. :bow:
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: terraforming rivers testing patch

Post by xarick »

water_cmd.cpp editing

Code: Select all

/**
 * Draw canal or river edges.
 * @param canal  True if canal edges should be drawn, false for river edges.
 * @param offset Sprite offset.
 * @param tile   Tile to draw.
 */
static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
{
	CanalFeature feature;
	SpriteID base = 0;
	if (canal) {
		feature = CF_DIKES;
		base = GetCanalSprite(CF_DIKES, tile);
		if (base == 0) base = SPR_CANAL_DIKES_BASE;
	} else {
		feature = CF_RIVER_EDGE;
		base = GetCanalSprite(CF_RIVER_EDGE, tile);
		if (base == 0) return; // Don't draw if no sprites provided.
	}

	uint wa;

	/* determine the edges around with water. */
	wa  = IsWateredTile(TILE_ADDXY(tile, -1,  0), DIR_SW) << 0;  // NE
	wa += IsWateredTile(TILE_ADDXY(tile,  0,  1), DIR_NW) << 1;  // SE
	wa += IsWateredTile(TILE_ADDXY(tile,  1,  0), DIR_NE) << 2;  // SW
	wa += IsWateredTile(TILE_ADDXY(tile,  0, -1), DIR_SE) << 3;  // NW

	Slope tileh = GetTileSlope(tile);
	if (!(wa & 1)) {
		DrawWaterSprite(base, offset, feature, tile);
		if (tileh == SLOPE_N) DrawWaterSprite(base, offset + 48, feature, tile);
		if (tileh == SLOPE_E) DrawWaterSprite(base, offset + 12, feature, tile);
	}
	if (!(wa & 2)) {
		DrawWaterSprite(base, offset + 1, feature, tile);
		if (tileh == SLOPE_E) DrawWaterSprite(base, offset + 25, feature, tile);
		if (tileh == SLOPE_S) DrawWaterSprite(base, offset + 37, feature, tile);
	}
	if (!(wa & 4)) {
		DrawWaterSprite(base, offset + 2, feature, tile);
		if (tileh == SLOPE_S) DrawWaterSprite(base, offset + 14, feature, tile);
		if (tileh == SLOPE_W) DrawWaterSprite(base, offset + 50, feature, tile);
	}
	if (!(wa & 8)) {
		DrawWaterSprite(base, offset + 3, feature, tile);
		if (tileh == SLOPE_W) DrawWaterSprite(base, offset + 39, feature, tile);
		if (tileh == SLOPE_N) DrawWaterSprite(base, offset + 27, feature, tile);
	}

	/* right corner */
	switch (wa & 0x03) {
		case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
	}

	/* bottom corner */
	switch (wa & 0x06) {
		case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
	}

	/* left corner */
	switch (wa & 0x0C) {
		case  0: DrawWaterSprite(base, offset + 6, feature, tile); break;
		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
	}

	/* upper corner */
	switch (wa & 0x09) {
		case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
	}
}


static void DrawRiverWater(const TileInfo *ti)
{
	SpriteID image = SPR_FLAT_WATER_TILE;
	uint     offset = 0;
	uint     edges_offset = 0;

	if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
		image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
		if (image == 0) {
			switch (ti->tileh) {
				case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
				case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP;   break;
				case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP;   break;
				case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
				default:       image = SPR_FLAT_WATER_TILE;    break;
			}
		} else {
			/* Flag bit 0 indicates that the first sprite is flat water. */
			offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;

			switch (ti->tileh) {
				case SLOPE_SE:              edges_offset += 12; break;
				case SLOPE_NE: offset += 1; edges_offset += 24; break;
				case SLOPE_SW: offset += 2; edges_offset += 36; break;
				case SLOPE_NW: offset += 3; edges_offset += 48; break;
				case SLOPE_E:  offset  = 0; edges_offset = 0; break;
				case SLOPE_S:  offset  = 0; edges_offset = 0; break;
				case SLOPE_W:  offset  = 0; edges_offset = 0; break;
				case SLOPE_N:  offset  = 0; edges_offset = 0; break;
				default:       offset  = 0; break;
			}

						offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
		}
	}

	DrawGroundSprite(image + offset, PAL_NONE);

	/* Draw river edges if available. */
	DrawWaterEdges(false, edges_offset, ti->tile);
}
This is the part I'm editing, to get the game to display the correct river edges, corners and small corners. And.... I have no idea what I'm doing.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: terraforming rivers testing patch

Post by xarick »

Used Paint for mixing and matching temperate grass with rapids, just to get an idea for myself of what is done, and what is missing. The images are in no way aligned! There seems to be missing more sets of images for mixing and matching edges, corners and small corners.
rapids_edit.png
(114.96 KiB) Not downloaded yet
Formerly known as Samu
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests