1
--------------------------------------------------------------------------------
2
--------------------------------------------------------------------------------
5
-- brief: returns a function that applies map options to a mapInfo table
6
-- author: Dave Rodgers
9
-- Licensed under the terms of the GNU GPL, v2 or later.
11
--------------------------------------------------------------------------------
12
--------------------------------------------------------------------------------
14
-- Special table for map config files
21
--------------------------------------------------------------------------------
22
--------------------------------------------------------------------------------
24
if (not Spring.GetMapOptions) then
25
return function (mapInfo)
26
-- map options not available (unitsync),
27
-- no need to modify the mapInfo table
32
--------------------------------------------------------------------------------
33
--------------------------------------------------------------------------------
35
local mapOptions = Spring.GetMapOptions()
38
--------------------------------------------------------------------------------
39
--------------------------------------------------------------------------------
41
local function ParseFloat3(value)
43
if (t == 'table') then
44
if (tonumber(value[1]) and
45
tonumber(value[2]) and
46
tonumber(value[3])) then
51
elseif (t == 'string') then
52
local s, e, v1, v2, v3 = value:find('^%s*(%S)%s+(%S)%s+(%S)%s*$')
56
if (v1 and v2 and v3) then
66
local function TintColor(color, tint)
75
local function SetColorComponent(color, component, value)
76
color = ParseFloat3(color)
81
if ((component == 1) or (component == 'r')) then
82
color[1] = tonumber(value)
83
elseif ((component == 2) or (component == 'g')) then
84
color[2] = tonumber(value)
85
elseif ((component == 3) or (component == 'b')) then
86
color[3] = tonumber(value)
95
--------------------------------------------------------------------------------
96
--------------------------------------------------------------------------------
98
local function UpdateBasics(mapInfo)
99
if (mapOptions.voidwater) then
100
mapInfo.voidwater = mapOptions.voidwater
102
if (mapOptions.notdeformable) then
103
mapInfo.notdeformable = mapOptions.notdeformable
105
if (mapOptions.hardness) then
106
mapInfo.hardness = mapOptions.hardness
108
if (mapOptions.gravity) then
109
mapInfo.gravity = mapOptions.gravity
111
if (mapOptions.extractorradius) then
112
mapInfo.extractorradius = mapOptions.extractorradius
114
if (mapOptions.tidalstrength) then
115
mapInfo.tidalstrength = mapOptions.tidalstrength
120
local function UpdateAtmosphere(mapInfo)
121
mapInfo.atmosphere = mapInfo.atmosphere or {}
122
local atmo = mapInfo.atmosphere
124
if (mapOptions.minwind) then
125
atmo.minwind = mapOptions.minwind
127
if (mapOptions.maxwind) then
128
atmo.maxwind = mapOptions.maxwind
130
if (mapOptions.clouddensity) then
131
atmo.clouddensity = mapOptions.clouddensity
137
local function UpdateWater(mapInfo)
138
mapInfo.water = mapInfo.water or {}
139
local water = mapInfo.water
141
if (mapOptions.waterdamage) then
142
water.damage = mapOptions.waterdamage
147
local function UpdateLighting(mapInfo)
148
mapInfo.lighting = mapInfo.lighting or {}
149
local lighting = mapInfo.lighting
151
if (mapOptions.tint) then
152
if (tint == 'dark') then end
154
if (mapOptions.grounddiffusecolor_r) then
155
lighting.grounddiffusecolor =
156
SetColorPart(lighting.grounddiffusecolor, 'r', mapOptions.grounddiffusecolor_r)
161
local function UpdateTerrainTypes(mapInfo)
162
mapInfo.terrain = mapInfo.terrain or {}
163
local terrain = mapInfo.terrain
167
--------------------------------------------------------------------------------
168
--------------------------------------------------------------------------------
170
return function(mapInfo)
172
UpdateBasics(mapInfo)
174
UpdateAtmosphere(mapInfo)
178
UpdateLighting(mapInfo)
180
UpdateTerrainTypes(mapInfo)
182
if (not mapInfo.description) then
183
mapInfo.description = Map.fileName
185
mapInfo.description = mapInfo.description .. ' (with MapOptions)'
189
--------------------------------------------------------------------------------
190
--------------------------------------------------------------------------------