~ubuntu-branches/ubuntu/natty/spring/natty

« back to all changes in this revision

Viewing changes to cont/base/maphelper/maphelper/applyopts.lua

  • Committer: Bazaar Package Importer
  • Author(s): Scott Ritchie
  • Date: 2010-09-23 18:56:03 UTC
  • mfrom: (3.1.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100923185603-st97s5chplo42y7w
Tags: 0.82.5.1+dfsg1-1ubuntu1
* Latest upstream version for online play
* debian/control: Replace (rather than conflict) spring-engine
  - spring-engine will be a dummy package (LP: #612905)
  - also set maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--------------------------------------------------------------------------------
 
2
--------------------------------------------------------------------------------
 
3
--
 
4
--  file:    applyopts.lua
 
5
--  brief:   returns a function that applies map options to a mapInfo table
 
6
--  author:  Dave Rodgers
 
7
--
 
8
--  Copyright (C) 2008.
 
9
--  Licensed under the terms of the GNU GPL, v2 or later.
 
10
--
 
11
--------------------------------------------------------------------------------
 
12
--------------------------------------------------------------------------------
 
13
 
 
14
-- Special table for map config files
 
15
--
 
16
--   Map.fileName
 
17
--   Map.fullName
 
18
--   Map.configFile
 
19
 
 
20
 
 
21
--------------------------------------------------------------------------------
 
22
--------------------------------------------------------------------------------
 
23
 
 
24
if (not Spring.GetMapOptions) then
 
25
  return function (mapInfo)
 
26
    -- map options not available (unitsync),
 
27
    -- no need to modify the mapInfo table
 
28
  end
 
29
end
 
30
 
 
31
 
 
32
--------------------------------------------------------------------------------
 
33
--------------------------------------------------------------------------------
 
34
 
 
35
local mapOptions = Spring.GetMapOptions()
 
36
 
 
37
 
 
38
--------------------------------------------------------------------------------
 
39
--------------------------------------------------------------------------------
 
40
 
 
41
local function ParseFloat3(value)
 
42
  local t = type(value)
 
43
  if (t == 'table') then
 
44
    if (tonumber(value[1]) and
 
45
        tonumber(value[2]) and
 
46
        tonumber(value[3])) then
 
47
      return value
 
48
    else
 
49
      return nil
 
50
    end
 
51
  elseif (t == 'string') then
 
52
    local s, e, v1, v2, v3 = value:find('^%s*(%S)%s+(%S)%s+(%S)%s*$')
 
53
    v1 = tonumber(v1)
 
54
    v2 = tonumber(v2)
 
55
    v3 = tonumber(v3)
 
56
    if (v1 and v2 and v3) then
 
57
      return { v1, v2, v3 }
 
58
    else
 
59
      return nil
 
60
    end
 
61
  end
 
62
  return nil
 
63
end
 
64
 
 
65
 
 
66
local function TintColor(color, tint)
 
67
  return {
 
68
    color[1] * tint[1],
 
69
    color[2] * tint[2],
 
70
    color[3] * tint[3],
 
71
  }
 
72
end
 
73
 
 
74
 
 
75
local function SetColorComponent(color, component, value)
 
76
  color = ParseFloat3(color)
 
77
  if (not color) then
 
78
    return false
 
79
  end
 
80
 
 
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)
 
87
  else
 
88
    return false
 
89
  end
 
90
 
 
91
  return true
 
92
end
 
93
 
 
94
 
 
95
--------------------------------------------------------------------------------
 
96
--------------------------------------------------------------------------------
 
97
 
 
98
local function UpdateBasics(mapInfo)
 
99
  if (mapOptions.voidwater) then
 
100
    mapInfo.voidwater = mapOptions.voidwater
 
101
  end
 
102
  if (mapOptions.notdeformable) then
 
103
    mapInfo.notdeformable = mapOptions.notdeformable
 
104
  end
 
105
  if (mapOptions.hardness) then
 
106
    mapInfo.hardness = mapOptions.hardness
 
107
  end
 
108
  if (mapOptions.gravity) then
 
109
    mapInfo.gravity = mapOptions.gravity
 
110
  end
 
111
  if (mapOptions.extractorradius) then
 
112
    mapInfo.extractorradius = mapOptions.extractorradius
 
113
  end
 
114
  if (mapOptions.tidalstrength) then
 
115
    mapInfo.tidalstrength = mapOptions.tidalstrength
 
116
  end
 
117
end
 
118
 
 
119
 
 
120
local function UpdateAtmosphere(mapInfo)
 
121
  mapInfo.atmosphere = mapInfo.atmosphere or {}
 
122
  local atmo = mapInfo.atmosphere
 
123
 
 
124
  if (mapOptions.minwind) then
 
125
    atmo.minwind = mapOptions.minwind
 
126
  end
 
127
  if (mapOptions.maxwind) then
 
128
    atmo.maxwind = mapOptions.maxwind
 
129
  end
 
130
  if (mapOptions.clouddensity) then
 
131
    atmo.clouddensity = mapOptions.clouddensity
 
132
  end
 
133
end
 
134
 
 
135
 
 
136
 
 
137
local function UpdateWater(mapInfo)
 
138
  mapInfo.water = mapInfo.water or {}
 
139
  local water = mapInfo.water
 
140
 
 
141
  if (mapOptions.waterdamage) then
 
142
    water.damage = mapOptions.waterdamage
 
143
  end
 
144
end
 
145
 
 
146
 
 
147
local function UpdateLighting(mapInfo)
 
148
  mapInfo.lighting = mapInfo.lighting or {}
 
149
  local lighting = mapInfo.lighting
 
150
 
 
151
  if (mapOptions.tint) then
 
152
    if (tint == 'dark') then end
 
153
  end
 
154
  if (mapOptions.grounddiffusecolor_r) then
 
155
    lighting.grounddiffusecolor =
 
156
      SetColorPart(lighting.grounddiffusecolor, 'r', mapOptions.grounddiffusecolor_r)
 
157
  end
 
158
end
 
159
 
 
160
 
 
161
local function UpdateTerrainTypes(mapInfo)
 
162
  mapInfo.terrain = mapInfo.terrain or {}
 
163
  local terrain = mapInfo.terrain
 
164
end
 
165
 
 
166
 
 
167
--------------------------------------------------------------------------------
 
168
--------------------------------------------------------------------------------
 
169
 
 
170
return function(mapInfo)
 
171
 
 
172
  UpdateBasics(mapInfo)
 
173
 
 
174
  UpdateAtmosphere(mapInfo)
 
175
 
 
176
  UpdateWater(mapInfo)
 
177
 
 
178
  UpdateLighting(mapInfo)
 
179
 
 
180
  UpdateTerrainTypes(mapInfo)
 
181
 
 
182
  if (not mapInfo.description) then
 
183
    mapInfo.description = Map.fileName
 
184
  end
 
185
  mapInfo.description = mapInfo.description .. ' (with MapOptions)'
 
186
end
 
187
 
 
188
 
 
189
--------------------------------------------------------------------------------
 
190
--------------------------------------------------------------------------------