Jump to content
XCOMUFO & Xenocide

How To Add Lua Maps Terrains, Instead Of Binary .maps?


bamb

Recommended Posts

Can you guys help me how to add LUA maps to a terrain. Not the .map binary old maps, but the new ones the javascript map maker saves.

 

My lua file is, after loading the tilestets, like this, which doesn't work (look at bada00.lua, if i replace it with dawn00.map, it works and the resulting battlescapes are all roads like they should be). It seems it can't even parse it as it doesn't show up in the map list if i try a hotseat game.

 

-----

 

AddXcomTerrain {

Name = "burbitest",

Tiles = {

"destroyed",

"dawn"

},

Maps = {

--Yes, just one map currently!--

"$(extension)/bada00.lua"

},

 

MapGenerator = function(tmp)

 

for i = 1, tmp.SizeY do

for j = 1, tmp.SizeX do

--all tiles are the same map currently--

tmp.Mapdata[j] = 00

end

end

return tmp

end

}

 

-----

 

So, is it some other command than AddXcomTerrain? I tried AddTerrain and AddLUATerrain but no avail. Is there some documentation somewhere? I tried searching this subforum but stuff ain't here. Thanks!

Link to comment
Share on other sites

Check this post

 

A thousand thanks, Hobbes! Now it loads up!

So you have to have AddTerrain and then the files NOT including the .lua filename extension.

Like this:

AddTerrain {

Name = "burbitest",

Tiles = {

"destroyed",

"dawn"

},

Maps = {

--Yes, just one map currently!--

--"$(extension)/bada00.lua"

"bada00"

},

 

But now I have another problem, the map loads up as completely destroyed!

http://img54.imageshack.us/img54/4457/dogparkuh4.png <- LUA map in editor

http://img54.imageshack.us/img54/2672/dogparksdestroid9.png <- LUA map in game

I'll continue experimenting..

 

EDIT:

OK, got it to work!!

I changed load order of dawn and destroyed tilesets so it loads dawn first.

http://img410.imageshack.us/img410/1311/dogworksoj8.png

Too bad one can walk through the park entry doors diagonally without having to open them. Them skinny humans! Maybe I have to edit the map.

 

Thanks a lot for your guys, help... I mean, help, guys!

Edited by bamb
Link to comment
Share on other sites

I made an entry yesterday about this on the Custom Maps page of the UFO2000 wiki.

 

I've also made some major changes from your initial entry, not that it they were wrong, I already had come with a basic idea for the page. What do you think of the contents so far?

Link to comment
Share on other sites

I made an entry yesterday about this on the Custom Maps page of the UFO2000 wiki.

 

I've also made some major changes from your initial entry, not that it they were wrong, I already had come with a basic idea for the page. What do you think of the contents so far?

 

I took a peak at the wiki entry and came out of it with some useful information that I wasn't aware of before. The script stuff is beyond me in most cases but it was broken down very clearly. I Appreciate that a lot. (I'll still get you to handle all of it bambuz LOL)

 

In regards to some entries in your mapping tips, there are points where I'd have to disagree as they are more opinion than fact.

 

Large maps or buildings can look very nice and be fun to build. Unfortunately, they also can turn boring and be difficult to play very easily. The same can happen with lots of small rooms, narrow corridors, lots of objects and maps with several levels.

 

 

It is best to keep terrains simple, with space for units to move and easy communications between maps.

 

are the two points in particular . The small group we've managed to rustle together actually craves more complex areas and more challenging areas to defend/attack. They can be especially fun other scenarios besides standard deathmatch. Of course too much, is too much, so a nice balance with open areas as well.  Variety being the spice of life after all.

Link to comment
Share on other sites

I managed to do a simple map generation code now. It took quite a while!

It first adds roads, then big buildings and lastly fills with small buildings the remaining space.

 

No road intersections yet... and the roads aint much finished anyway yet. Nor any fitting of buildings together/to roads.

 

There should be much more documentation so doing all would be much much much easier. Even LUA docs are down.

I used this then:http://www.autoitscript.com/autoit3/scite/docs/Lua_Doc/manual.html

 

But the code (the tabs are broken for some reason):

MapGenerator = function(tmp)
--- helper funcs ---

	--randomly select a value from a vector of length len
	local function random_pick(veccis,len)
		local indi = math.floor(math.random(1,len+1))
		return veccis[indi]
	end


	--fill scape with one style
	local function fill_scape(scape,fillwith)
		for i = 1, scape.SizeY do
			for j = 1, scape.SizeX do
				--all tiles are the same map currently--
				scape.Mapdata[i][j] = fillwith
			end
		end
	end



	-- get random location along x axis
	-- (works for y too since battlescapes are square)

	local function random_x(scape)
		--local temp=math.random(1,tmp.SizeX)
		--return temp
		if(scape.SizeX==4) then
			return random{1,2,3,4}
		end

		if(scape.SizeX==5) then
			return random{1,2,3,4,5}
		end

  			if(scape.SizeX==6) then
			return random{1,2,3,4,5,6}
		end

	end

	local function random_x_less(scape)
		--local temp=math.random(1,tmp.SizeX)
		--return temp
		if(scape.SizeX==4) then
			return random{1,2,3}
		end

		if(scape.SizeX==5) then
			return random{1,2,3,4}
		end

  			if(scape.SizeX==6) then
			return random{1,2,3,4,5}
		end

	end


	--get x size of a tile--
	local function get_dx(segnumber)
		if (segnumber==3 or segnumber==4 or segnumber==5 or segnumber==6) then
			return 2
		end
		if (segnumber>=7 and segnumber <= 15) then --roads
			return 2
		end
		return 1
	end

	--get y size of a tile--
	local function get_dy(segnumber)
		if (segnumber==2 or segnumber==3 or segnumber==6) then
			return 2
		end
		return 1
	end

	--get random big tile
	local function random_big()
		return random{2,3,4,5,6}
		--return 3
	end

	local function random_small()
--g			return random_pick({1,0},2)
		return random{0,1}
	end


  --check if dx*dy size piece fits at x,y (upper left corner) in battlescape scape
	local function will_it_fit(scape,x,y,dx,dy)
		local final_x = x+dx-1
		local final_y = y+dy-1


		--check edge overboarding
		if((final_x>scape.SizeX) or (final_y>scape.SizeY)) then
			return 0
		end

		--check if there's something in the way
		for i = x, final_x do
			for j = y, final_y do
				if(scape.Mapdata[j][i] ~= -2) then
					--tile is not free
					return 0
				end
			end
		end
		return 1
	end

	--place a big building (map) in the battlescape
	local function apply_big(scape,x,y,dx,dy,bignum)
		local final_x = x+dx-1
		local final_y = y+dy-1

		for i = x, final_x do
			for j = y, final_y do
					scape.Mapdata[j][i] = -1
			end
		end
		scape.Mapdata[y][x]=bignum
	end

	--try to put a big building at x,y if it will fit
	local function put_big(scape,bignum,try_x,try_y)

		local try_dx = get_dx(bignum)
		--local try_dy=2
		local try_dy = get_dy(bignum)

		if will_it_fit(scape,try_x,try_y,try_dx,try_dy)==1 then
			--tmp.Mapdata[1][1]=3
			--tmp.Mapdata[1][2]=-1
			--tmp.Mapdata[2][1]=-1
			--tmp.Mapdata[2][2]=-1
			apply_big(scape,try_x,try_y,try_dx,try_dy,bignum)
		end
	end

--- main ---

	--initialization
	fill_scape(tmp,-2)

	--make some roads

	local xroad_y=0
	local yroad_x=0

	local xroad_num=7 --what map to use for horiz roads
	local yroad_num=8 --what map to use for vert roads


	--horizontal road (50% chance of existence)
	if (random{false,true}) then
--		if 0 then
		xroad_y=random_x(tmp)
		xroad_num=7
		for i=1,tmp.SizeX-1 do --remember roads are 2x1
			put_big(tmp,xroad_num,i,xroad_y)
		end

	end

	--vertical road (50% chance of existence)
	if (random{false,true}) then
--		if random{0,1} then
		yroad_x=random_x_less(tmp) --roads are 2x1 so not at edge, use _less
		local yroad_num=8
		for i=1,tmp.SizeY do
			put_big(tmp,yroad_num,yroad_x,i)
		end
	end

	--local crossing_num=9

	-- a crossing is needed, later
--		if(xroad_y and yroad_x) then
--			tmp.Mapdata[xroad_y][yroad_x]=crossing_num
--	   end


	--try to fit some big buildings
	for i = 1, 8 do --try 8 times
		local try_x=random_x_less(tmp)
		local try_y=random_x_less(tmp)
		--local try_x=1;
		--local try_y=1;
		--local try_segnum=3
		local try_segnum = random_big()
		--local try_dx=2
		put_big(tmp,try_segnum,try_x,try_y)
	end


	-- put small buildings in empty places
	for i = 1, tmp.SizeY do
			for j = 1, tmp.SizeX do
				--all tiles are the same map currently--
				if(tmp.Mapdata[i][j]==-2) then
					tmp.Mapdata[i][j]=random_small()
				end
			end
	 end


	--debug for now, let's not try anything fancy actually
	--fill_scape(tmp,01)

	--debug!!!
--		for i=1,tmp.SizeX do
--		   for j=1,tmp.SizeY do
--			   tmp.Mapdata=00
--			end
--		end


	return tmp
end
}

Link to comment
Share on other sites

In regards to some entries in your mapping tips, there are points where I'd have to disagree as they are more opinion than fact.

 

Large maps or buildings can look very nice and be fun to build. Unfortunately, they also can turn boring and be difficult to play very easily. The same can happen with lots of small rooms, narrow corridors, lots of objects and maps with several levels.

It is best to keep terrains simple, with space for units to move and easy communications between maps.

 

are the two points in particular . The small group we've managed to rustle together actually craves more complex areas and more challenging areas to defend/attack. They can be especially fun other scenarios besides standard deathmatch. Of course too much, is too much, so a nice balance with open areas as well.  Variety being the spice of life after all.

 

The game server stats are offline but the tendency observed over the years on online games is that open terrains such as City, Modified City, Industrial, Farm, etc., make up at least 75% of all games played online. The remaining 25% or less are played on XBase, Warehouse and other terrains (those are examples of what I mean by complex maps). So, it is not an opinion but a fact: players in general prefer straight forward terrains :)

 

I have nothing against such complex terrains (I've designed a few of them myself: check Native, Polis or Siberia on the map depot). But don't expect for them to be used by a lot of players. And it can be a waste of time to spend countless hours designing a terrain only to find out that almost no one plays it.

Link to comment
Share on other sites

I managed to do a simple map generation code now. It took quite a while!

It first adds roads, then big buildings and lastly fills with small buildings the remaining space.

 

No road intersections yet... and the roads aint much finished anyway yet. Nor any fitting of buildings together/to roads.

 

There should be much more documentation so doing all would be much much much easier. Even LUA docs are down.

 

There's code already written to perform the functions you have described, especially on Dawn City, which can be adapted but it can be challenging to figure it out.

Link to comment
Share on other sites

There's code already written to perform the functions you have described, especially on Dawn City, which can be adapted but it can be challenging to figure it out.

 

Yeah we've been using it as a sort of basis for the 'burbs' set we're creating. Of course it's going to be fairly different in some aspects because we're using a different road scheme and don't have any 'modular' type buildings (at least not yet, hah)

 

we're gettin there :)

 

 

 

 

 

 

Native is a blast to play in search & destroy...post-13780-1177911569_thumb.png

Link to comment
Share on other sites

There's code already written to perform the functions you have described, especially on Dawn City, which can be adapted but it can be challenging to figure it out.

 

Yeah we've been using it as a sort of basis for the 'burbs' set we're creating. Of course it's going to be fairly different in some aspects because we're using a different road scheme and don't have any 'modular' type buildings (at least not yet, hah)

 

we're gettin there :)

 

Native is a blast to play in search & destroy...post-13780-1177911569_thumb.png

 

Yeah, I looked at the dawn city scripts, and they served as an example, but I made my own from scratch, as they seemed so complex and there was little documentation so it was hard to understand what was going on. :)

 

For example, the random{} overloaded function is not documented, but works pretty straightforward. Maybe all this will one day be in the wiki.

I'll work on the documentation to the wiki in a few days, after you, Hobbes, of course.

Link to comment
Share on other sites

Yeah, I looked at the dawn city scripts, and they served as an example, but I made my own from scratch, as they seemed so complex and there was little documentation so it was hard to understand what was going on. :)

 

There's probably a dozen ways to make the dawn city scripts simpler but I've learned .lua all by myself without even knowing any programming, so they might be a little complex.

 

For example, the random{} overloaded function is not documented, but works pretty straightforward. Maybe all this will one day be in the wiki.

I'll work on the documentation to the wiki in a few days, after you, Hobbes, of course.

 

Go ahead and add what you think is necessary to the wiki. To be honest I'm not sure I'll be able to fill it more for the time being since I basically adapt existing code to my needs and know few of the logic underneath it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...