-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathseasonsUltimaFix.lua
68 lines (52 loc) · 3.04 KB
/
seasonsUltimaFix.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
----------------------------------------------------------------------------------------------------
-- ULTIMA PATCH SCRIPT
----------------------------------------------------------------------------------------------------
-- Purpose: Fix Krone Ultima from BM-modding to use Seasons bale wrapping features.
-- Authors: baron
--
-- Copyright (c) Realismus Modding, 2017
----------------------------------------------------------------------------------------------------
Mission00.loadMission00Finished = Utils.appendedFunction(Mission00.loadMission00Finished, function (...)
local ultimaModName = "FS17_KroneUltimaCF155XC"
local envUltima, ssBaleManager = nil, nil
if g_modIsLoaded[ultimaModName] then
envUltima = getfenv(0)[ultimaModName]
end
if g_seasons ~= nil then
ssBaleManager = g_seasons.baleManager
end
if envUltima ~= nil and ssBaleManager ~= nil then
-- Inject the code required for Seasons when Ultima.wrapperDropBale() is called
envUltima.Ultima.wrapperDropBale = Utils.prependedFunction(envUltima.Ultima.wrapperDropBale, function (self)
local bale = self.wrapperCurrentBale.baleObject
-- If fillType is silage, the Ultima bale is assumed to be wrapped
if bale.fillType == FillUtil.FILLTYPE_SILAGE then
-- wrappingState must be set to 1 for Seasons to recognize the bale as weather protected
bale.wrappingState = 1
-- pass baleObject to Seasons
self.lastDroppedBale = bale
-- pass source fillType to Seasons
self.baleFillTypeSource = self.wrapperCurrentBale.fillType
-- call the necessary Seasons function to enable all mechanics for wrapped bales
-- self is assumed to be of class BaleWrapper (only needs self.lastDroppedBale and self.baleFillTypeSource)
ssBaleManager.baleWrapperDoStateChange(self, BaleWrapper.CHANGE_WRAPPER_BALE_DROPPED, nil)
end
end)
end
end)
-- In savegame, store and retrieve Bale.wrappingState for bales regardless of Bale.supportsWrapping
-- to enable Seasons to properly recognize wrapped bales from the ultima, as the ultima does
-- do wrapping without setting supportsWrapping correctly to a positive value
-- (another solution would be to have the user attribute supportsWrapping set to true in the i3d)
Bale.getSaveAttributesAndNodes = Utils.overwrittenFunction(Bale.getSaveAttributesAndNodes, function(self, superFunc, nodeIdent)
local attributes, nodes = superFunc(self, nodeIdent)
if not self.supportsWrapping and self.wrappingState ~= nil then
attributes = attributes .. ' wrappingState="'..tostring(self.wrappingState)..'"'
end
return attributes, nodes
end)
Bale.loadFromAttributesAndNodes = Utils.overwrittenFunction(Bale.loadFromAttributesAndNodes, function(self, superFunc, xmlFile, key, resetVehicles)
local state = superFunc(self, xmlFile, key, resetVehicles)
self.wrappingState = getXMLFloat(xmlFile, key.."#wrappingState")
return state
end)