-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdata-updates.lua
51 lines (47 loc) · 1.28 KB
/
data-updates.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local fuel_values = {
["crude-oil"] = "1.4MJ",
["light-oil"] = "1.5MJ",
["heavy-oil"] = "1MJ",
["petroleum-gas"] = "1.5MJ",
["diesel-fuel"] = "2MJ",
}
local emissions = {
["crude-oil"] = 1.4,
["light-oil"] = 1.2,
["heavy-oil"] = 1.3,
["petroleum-gas"] = 1,
["diesel-fuel"] = 0.8,
}
local parse_energy = function(energy)
local ending = energy:sub(energy:len())
if not (ending == "J" or ending == "W") then
error(ending.. " is not a valid unit of energy")
end
local magnitude = energy:sub(energy:len() - 1, energy:len() - 1)
local multiplier = 1
if type(magnitude) == "number" then
return tonumber(energy:sub(1, energy:len()-1))
end
local char = {
k = 1000,
M = 1000000,
G = 1000000000,
T = 1000000000000,
P = 1000000000000000,
E = 1000000000000000000,
Z = 1000000000000000000000,
Y = 1000000000000000000000000
}
multiplier = char[magnitude]
if not multiplier then error(magnitude.. " is not valid magnitude") end
return tonumber(energy:sub(1, energy:len()-2)) * multiplier
end
local names = {}
for k, fluid in pairs (data.raw.fluid) do
if not fluid.fuel_value then
fluid.fuel_value = fuel_values[fluid.name]
end
if not fluid.emissions_multiplier then
fluid.emissions_multiplier = emissions[fluid.name]
end
end