All pastes #501808 Raw Edit

Rick

public text v1 · immutable
·published 2007-05-22 06:49 UTC
rendered paste body
global mineRectangle = function(g, x, y, width, height)
{
	for (cx = x; cx < x + width; cx = cx + 1)
	{
		for (cy = y; cy < y + height; cy = cy + 1)
		{
			symbol = g.mapGetTileSymbol(cx, cy);
			designation = g.mapGetTileDesignation(cx, cy);
			
			if ((designation & 0x80) == 0 && g.isSymbolMinable(symbol))
			{
				g.mapSetBlockActive(cx, cy, true);
				g.mapSetTileDesignation(cx, cy, designation | 0x80);
			}
		}
	}
};

global findLiquidEdge = function(g, sx, sy, height)
{
	if (sx < 0 || sx >= g.mapWidth)
	{
		return -1;
	}
	
	for (y = sy; y < sy + height; y = y + 1)
	{
		symbol = g.mapGetTileSymbol(sx, y);
		
		if (symbol == g.SYMBOL_FLUID)
		{
			return sx;
		}
	}
	
	return findLiquidEdge(g, sx + 1, sy, height);
};

global findLiquidWall = function(g, sx, sy, height)
{
	if (sx < 0 || sx >= g.mapWidth)
	{
		return -1;
	}
	
	for (y = sy; y < sy + height; y = y + 1)
	{
		symbol = g.mapGetTileSymbol(sx, y);
		
		if (symbol != g.SYMBOL_FLUID)
		{
			return findLiquidWall(g, sx + 1, sy, height);
		}
	}
	
	return sx;
};

global findMinableWall = function(g, sx, sy, height)
{
	if (sx < 0 || sx >= g.mapWidth)
	{
		return -1;
	}
	
	for (y = sy; y < sy + height; y = y + 1)
	{
		symbol = g.mapGetTileSymbol(sx, y);
		
		if (g.isSymbolMinable(symbol) == false)
		{
			return findMinableWall(g, sx - 1, sy, height);
		}
	}
	
	return sx;
};

global modifyMap = function(g)
{
	// This is how the game currently gets your 'gate' position.
	entranceX = g.mapUndergroundX;
	entranceY = (g.mapHeight / 2);
	
	// Boink.
	entranceY = entranceY + 10;
	
	//edge = findRiverEdge(g, entranceX);
	edge = findLiquidEdge(g, entranceX, entranceY - 2, 5);
	
	if (edge == -1)
	{
		print("Failed to find river edge.\n");
		return;
	}
	
	breach = findMinableWall(g, edge, entranceY - 2, 5);
	breach = breach - 2; // Make sure we have at least 2 tiles of floor next to the river.
	
	// Clip the cliff
	mineRectangle(g, entranceX - 2, entranceY - 2, 2, 5);
	
	// Outside door.
	mineRectangle(g, entranceX, entranceY, 1, 1);
	
	// Hallway
	mineRectangle(g, entranceX + 1, entranceY - 2, breach - entranceX - 1, 5);
	
	// River door
	mineRectangle(g, breach, entranceY, 1, 1);
	
	riverbed = findLiquidWall(g, breach + 1, entranceY - 2, 5);
	
	// River area
	mineRectangle(g, breach + 1, entranceY - 2, riverbed - breach, 5);
};

global main = function()
{
	g = Game();
	
	if (g.Open() == false)
	{
		print("Failed to open Dwarf Fortress!\n");
		return -1;
	}
	
	if (g.Suspend() == false)
	{
		print("Failed to suspend Dwarf Fortress!\n");
		g.Close();
		return -1;
	}
	
	if (g.mapIsAvailable)
	{
		modifyMap(g);
	}
	else
	{
		print("Please enter Dwarf Fortress mode.\n");
	}
	
	if (g.Resume() == false)
	{
		print("Failed to resume Dwarf Fortress!\n");
	}
	
	g.Close();
	return 0;
};

print("Rick's Tile Tool for Dwarf Fortress (v0.23.130.23a)\n\n");