Page 1 of 1

Map Scripting

Posted: Wed Dec 22, 2021 9:25 am
by Jace11
I've been tinkering with the random map generation script. Looking mostly at removing some of the more frequent artifacts. One I quite often see is single track tiles along coastlines, see pic...
It looks like a road, which possibly ran where I drew the red line, is erased by coast leaving multiple single track tiles (magenta).
Image

So script wise, as this seems to occur only with coasts I thought a check like:

Code: Select all

FUNCTION BM_RemoveVestigialTracks()
{
	int x;
	int y;
	int width;
	int height;
	int data;
	int j;
	int attempts;
	int any_found;

	width = GetMapWidth();
	height = GetMapHeight();

	attempts = 100;
	any_found = 1;
	for (j = 0; (j < attempts) && (any_found == 1); j++)
	{
		any_found = 0;
		for (x = 16; x <= width - 17; x++)
		{
			for (y = 16; y <= height - 17; y++)
			{
				data = BM_GetTileDataX(x, y, 1);
				if (data == 6)
					{
						if ((BM_GetTileDataX(x, y+1, 1) != 6) && (BM_GetTileDataX(x-1, y, 1) != 6) && (BM_GetTileDataX(x, y-1, 1) != 6) && (BM_GetTileDataX(x+1, y, 1) != 6))
							{
								any_found = 1;
								SetValidTileData(x,y,1,0);	
							}
					}
			}
		}
	}
}
might work, it probably doesn't need the multiple attempts part, I adapted an existing function. They are quite hard to follow, but also hard to test.

I've tried using it in the main script after FinaliseCoast function and it seems to work, but again its very hard to test.

if (coast == 1)
{
BM_FinaliseCoast();
BM_RemoveVestigialTracks();
}


If I remove the repeated attempts, and the width height limits, it looks like this:

Code: Select all

FUNCTION BM_RemoveVestigialTracks()
{
	int x;
	int y;
	int width;
	int height;
	int data;

	width = GetMapWidth();
	height = GetMapHeight();

	for (x = 0; x < width; x++)
	{
		for (y = 0; y < height; y++)
		{
			data = BM_GetTileDataX(x, y, 1);
			if (data == 6)
				{
					if ((BM_GetTileDataX(x, y+1, 1) != 6) && (BM_GetTileDataX(x-1, y, 1) != 6) && (BM_GetTileDataX(x, y-1, 1) != 6) && (BM_GetTileDataX(x+1, y, 1) != 6))
						{
							SetValidTileData(x,y,1,0);	
						}
				}
		}
	}
}
This seems more correct

Re: Map Scripting

Posted: Thu Dec 23, 2021 7:15 am
by rbodleyscott
Useful. I will probably look at adding that into the main game after testing.