Page 1 of 1

[Script] Fill void with walls

Posted: Tue Nov 11, 2014 8:34 pm
by alois
Hi all!

If one tries different elevations in a forest, or in a beach scenario, one immediately finds that - differently to what happens with dungeons and mines, for example - zones with different elevations are not automatically filled (there is no "forest wall" as there is a "dungeon wall"; I mean, there is, but it is not "vertical"!); thus, if one wants to make zones with different elevations using outdoor tiles, one has to build the walls one by one: a rather difficult task (is the facing correct? the elevation? etc.).

I've therefore written the following code which "fills in the blanks", adding "dungeon_walls" to compensate for the lack of a beach/forest wall. Just draw a map outdoors with different elevations (set the ceiling to 7 to avoid unpleasant surprises...), either using the beach ground tile, or the forest ground tile (or both), and then connect a pressure plate to the "makeWalls()" function in the script below. Step on the plate, and it's done!

Code: Select all

function makeWalls()
	local map = self.go.map
	local inix,finx = 0,31 -- the full map, change as you like
	local iniy,finy = 0,31 -- the full map, change as you like
	local list = {
		"dungeon_wall_01",
		"dungeon_wall_02",
	}
-- also: local list = {"forest_elevation_edge"}
	for x = (inix+1),(finx-1),1 do
		for y = (iniy+1),(finy-1),1 do
			local tilec = map:getAutomapTile(x,y)
			local elevc = map:getElevation(x,y)
			if (tilec == 1) or (tilec == 0) then -- 0 and 1 are the automap tiles for beach ground and forest ground
				for dir = 0,3,1 do
					local dx,dy = getForward(dir)
					local tilen = map:getAutomapTile(x+dx,y+dy)
					local elevn = map:getElevation(x+dx,y+dy)
					if ((tilen == 1) or (tilen == 0)) and (elevc < elevn) then
						for elev = elevc,(elevn-1),1 do
							local ran = math.random(#list)
							spawn(list[ran],party.party.level,x,y,dir,elev)
						end
					end
				end
			end
		end
	end
end
Here are the screenshots of the map, and the rendering before/after stepping on the pressure plate connected to the script

Image

Image

Image

Now, if only it were possible to save a file from the editor to disk, one could create the map, let the script add the walls, save their positions to disk, and copy the file inside dungeon.lua...

Alois :)

Re: [Script] Fill void with walls

Posted: Wed Nov 12, 2014 9:36 am
by antti
Instead of the dungeon walls, I suggest you to try out "forest_elevation_edge". It's the walls which are used on the river banks and such so it should be compatible with forest and beach ground.

Re: [Script] Fill void with walls

Posted: Wed Nov 12, 2014 9:51 am
by alois
antti wrote:Instead of the dungeon walls, I suggest you to try out "forest_elevation_edge". It's the walls which are used on the river banks and such so it should be compatible with forest and beach ground.
Done: thanks!

Any chances to see a function to save a file to disk from within an editor run? :)

Alois :)