MapOptions.lua and possible usefull functions ? *Request*

MapOptions.lua and possible usefull functions ? *Request*

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
SirArtturi
Posts: 1164
Joined: 23 Jan 2008, 18:29

MapOptions.lua and possible usefull functions ? *Request*

Post by SirArtturi »

Hello!

I think this MapOptions.lua is quite cool thing, but so far havent seen any in real use. I think reason to this is that theres actually no usefull functions you could add to it (Or anyone to make these functions.)

What I'm personally looking for is for example:

Max Metal
Max and min wind speed
Hardness
Gravity
TidalStrength
Typemap = "true/false"
Water Damage = true/false
AI Bonus

So I need someone to help me out a little... How can i make gadget to LuaGaia that would give access to manipulate .smd file ? Or is there other way to do this ?
Attachments
MapOptions.lua
(4.96 KiB) Downloaded 138 times
Last edited by SirArtturi on 27 Oct 2008, 17:55, edited 1 time in total.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

As example lets make SmallDivide have maphardness as map option.

1)
Write the .smd file in LUA, instead of TDF format (don't change extension!):

Code: Select all

local mapInfo = {
  maphardness = 100.0,
  // TODO: convert other SmallDivide tags to LUA
}
return mapInfo
2)
Add MapOptions.lua to the map (root of the archive, ie. next to the maps folder in the archive):

Code: Select all

SmallDivide.sdd/
|-- MapOptions.lua
`-- maps
    |-- SmallDivide-MapOptions.smd
    |-- SmallDivide-MapOptions.smf
    `-- SmallDivide.smt
(I renamed this test map to "SmallDivide-MapOptions.smf", as you can see.)

3)
Add the following to MapOptions.lua:

Code: Select all

local options =
{
  {
    key    = 'maphardness',
    name   = 'Hardness',
    desc   = 'How much the map deforms due to explosions',
    type   = 'number',
    def    = 100.0,
    min    = 0,
    max    = 500.0,
    step   = 10.0,  -- quantization is aligned to the def value
                    -- (step <= 0) means that there is no quantization
  },
}
return options
This will add map option to lobbies with which you can change hardness to any value (in steps of 10) between 0 and 500.

4)
As last step, we need to make the .smd file read the map option, instead of having the value hardcoded in there. To do this, we get the map options table from Spring, and use this to read back all the map options from from the lobby:

Code: Select all

local mapOptions = Spring.GetMapOptions()

local mapInfo = {
  maphardness = mapOptions.maphardness,
  // TODO: convert other SmallDivide tags to LUA
}
return mapInfo
5)
Profit! Test it with mapoption-compliant lobby and you should be able to freely change hardness to about anything between 0 and 500.

Others can help you with LUA details btw.

Good luck with it :-)
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

Hmm I think my example needs a check for when map info is being loaded in unitsync and Spring.GetMapOptions is nil.

I suppose now only engine default values would be visible in the lobby for all map parameters.

Probably want last step like this (untested pseudocode, my LUA isn't fluid enough yet...):

Code: Select all

local mapInfo = {
  maphardness = 100.0,
  // TODO: convert other SmallDivide tags to LUA
}
if (Spring.GetMapOptions != nil) {
  local mapOptions = Spring.GetMapOptions()
  mapInfo.maphardness = mapOptions.maphardness
}
return mapInfo
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by lurker »

Hardness 0?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

I tried it, gives nice infinite depth holes :-)

When you move camera over them screen turns entirely blue.

And then it crashes :-)
User avatar
SirArtturi
Posts: 1164
Joined: 23 Jan 2008, 18:29

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by SirArtturi »

Okay... Cool thing that it could be done this way, but is there way to do it without turning .smd TDF into LUA ?

Im having problems turning .smd into lua here's the file:
http://pastebin.com/m7df9bd29

Im so noob at this :(

Whatsoever here is MapOptions.lua I would like to implement:
Attachments
MapOptions.lua
(4.96 KiB) Downloaded 140 times
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

Can't really help you cause I'm LUA noob too, but I noticed some things:

Code: Select all

local mapOptions = Spring.GetMapOptions()
[...]
maphardness = (mapOptions and mapOptions.maphardness)
I don't think this works as variant for what I suggested: the entire function GetMapOptions does not exist when the map is parsed in unitsync. That's different from the function existing but returning nil.

Code: Select all

	team0 = {

		startPosX = 1364,
		startPosZ = 4494,

	},

	team1 = {
		
		startPosX = 7889,
		startPosZ = 4494,

	},
	[...]
If I understood the Spring code correctly, this needs to be more like this (though I can't get it working either...), because it gets a subtable "teams" from there in an indexed subtable, and there in a subtable called "startPos":

Code: Select all

teams = {
  { startPos = { x = 1364, z = 4494 } },
  { startPos = { x = 7889, z = 4494 } },
  -- etc.
}
I don't know either about exact tags for the other variables, will have to reverse engineer more code sometime.

I don't think map options can be done without turning the .smd into LUA. It should be possible though to rename the original .smd and call the LUA TDF parser in your .smd but this will just make stuff complexer...

EDIT: poke some LUA guru in #lua maybe :-)
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by trepan »

A couple of hints:
- MapOptions can be used with TDF *.smd files
- maps are loaded via mapinfo.lua, take a look there
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

trepan, maybe give useful info actually?

of course I know they get loaded via mapinfo.lua I've been reverse engineering that code for a while to make first post...



Update on how to define start positions in LUA .smd:

Code: Select all

local mapInfo = {
  -- TODO: all other tags
}

-- load start positions
local teams = {}

teams[0] = { startPos = { x = 100.0, z = 100.0 } }
teams[1] = { startPos = { x = 200.0, z = 100.0 } }
teams[2] = { startPos = { x = 300.0, z = 100.0 } }
teams[3] = { startPos = { x = 400.0, z = 100.0 } }

mapInfo.teams = teams
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by trepan »

"MapOptions can be used with TDF *.smd files" -- not useful?

At the end of mapinfo.lua:

Code: Select all

if (Spring.GetMapOptions and mapInfo.defaultoptions) then
  local optsFunc = VFS.Include('maphelper/applyopts.lua')
  optsFunc(mapInfo)
end
Note that there's also a setupopts.lua in the same directory.

Sorry for having wasted your time with the previous post, will
try to keep the following in mind:
(less spring posts) > (more spring posts)
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

Well I noticed that line but it also causes other stuff I couldn't immediately figure out, and I couldn't see mapinfo.lua or dependencies (the map tdf parser) defining mapInfo.defaultoptions anywhere.

So you'd still need a LUA'ed .smd to set mapInfo.defaultoptions, right?

IOW, it's nice you point out that that line is there, but I've no clue what to do with that information without more instructions or without reverse engineering the rest of the code: which I'd have to do anyway even without the hint.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Tobi »

Edit: nm this doesn't work
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by trepan »

Fair enough. You're right, I'm wrong. Have fun ;-)
User avatar
SirArtturi
Posts: 1164
Joined: 23 Jan 2008, 18:29

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by SirArtturi »

Ok heres the smd right now:

http://pastebin.com/m2c9a8aee

Map loads now properly without errors. However seems that, while global parametres and start positions work properly, everything else is loaded by mapdefaults... (athmosphere, lightning, water etc.)

Whatsoever, from issue to another:
Im still wondering if theres no possibility to do this without "manually" converting smd into lua. if we could include somekinda of converter/parser with other lua that it could be possible to leave smd as it is...

This would make possible to use these mapoptions by other mappers aswell without learning to write their smds into lua first..

I wanted to make lua that could be easily used by mappers like "just attach the files into your map directory!"

maybe that parse_tdf_map.lua parser could be changed to produce lua code instead of actually making that data structure ?
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by REVENGE »

Tbh, it's pretty trivial to write your mapdefs in lua, just a couple of extra braces and whatnot right? I mean, you're not actually writing any code, just writing the mapdefs using lua formatting rules.

Also, the map editors by frostregen and sefidel should start writing smds by default using lua.
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by Gota »

Thing is.
You need to have presets.
People will not just waste play time on testing some random value with a map.
Most people do not even look there.

Stuff like animations of birds in the trees or wildlife or maybe some atmospheric effects...that would be hot..
Imagine you new map,Eye of Horus,with light dust storms coming randomly along with sound effects of a dust storm..
Or meteor showers.
Light rain if the map looks all swampy or just grim and wet.
rays of flickering light if the map is sunny..that's what will give maps a more natural feel to them..give them some character.
Nobody is really gonna play with tens of different values when he hosts a game..people like to play a map study it and know how to play on it to develop a sorted out gameplay.like a musician needing to know the technique to than improvise using that basis.
Players don't like to start playing a familiar map with some random experimental options that will probably not be used again and will just waste their time.
IMO any changes to maps need to be compulsory and permanent.
If the changes are cosmetic than you need a few presets that will only slightly modify the way the map looks but not how it plays.

Like a stormy preset sunny preset cold preset etc.
That will be something people will want to use.
Play the same familiar map but make it look slightly different and fresh.
User avatar
SirArtturi
Posts: 1164
Joined: 23 Jan 2008, 18:29

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by SirArtturi »

Gota wrote:Thing is. You need to have presets. People will not just waste play time on testing some random value with a map. Most people do not even look there. Stuff like animations of birds in the trees or wildlife or maybe some atmospheric effects...that would be hot..


There would still be the presets. and the presets are the settings that mapper have set. Changing these settings some people might find meaningless and waste of time but there are still some who would like to play around and adjust the map for their own taste...

I understand your point and agree with most of it... Well maybe those athmospherical settings and such are quite useless to be included because they are only for visual look. You can still modify the map in smd for screenshots or whatsoever. It doesnt have much global effect or effects on multiplaying dimensions.

my mapoptions lua are to make maps more flexible towards the style of gameplay you want. As also for maps that "fail" in some of these conditions. For example: DSD and folsomdamfinals typemap works with ba, but it may fail drastically for other mods, therefore it would be really nice option to turn off the typemap...

What comes natural effect luas, lups and such, I'd really like to include such luas you mention but there's none ! and no one is willing or skilled to make such things...

Other point is that these are options that are customable by your own choice. From now on, hopefully, you can easily add whatever you like to your mapoptions, whether it is gaia effects, athmospheric or global parametres etc...
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by smoth »

I am just poking in asking for 3 other options

skyboxsun
skyboxclouds


just a bool that would allow us to also render the sun and cloud layer along with our skybox image.

Fogstartdistance

numeric saying how far away the fog will start.

name it what you want but they would be handy tags.

I hope this was the type of input you wanted SirArtturi, I am still terribly ill so I am not able to read the whole thread, sorry if I am repeating something already posted
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by jK »

smoth wrote: Fogstartdistance

numeric saying how far away the fog will start.
like fogStart? ...
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: MapOptions.lua and possible usefull functions ? *Request*

Post by smoth »

oh yeah, so we do, then I guess I meant fogend.

I knew we had one or another.
Post Reply

Return to “Lua Scripts”