66 | function PlaceableClearAreas:loadClearArea(xmlFile, key, area) |
67 | local start = xmlFile:getValue(key .. "#startNode", nil, self.components, self.i3dMappings) |
68 | if start == nil then |
69 | Logging.xmlWarning(xmlFile, "Clear area start node not defined for '%s'", key) |
70 | return false |
71 | end |
72 | |
73 | local width = xmlFile:getValue(key .. "#widthNode", nil, self.components, self.i3dMappings) |
74 | if width == nil then |
75 | Logging.xmlWarning(xmlFile, "Clear area width node not defined for '%s'", key) |
76 | return false |
77 | end |
78 | |
79 | local height = xmlFile:getValue(key .. "#heightNode", nil, self.components, self.i3dMappings) |
80 | if height == nil then |
81 | Logging.xmlWarning(xmlFile, "Clear area height node not defined for '%s'", key) |
82 | return false |
83 | end |
84 | |
85 | area.start = start |
86 | area.width = width |
87 | area.height = height |
88 | |
89 | return true |
90 | end |
48 | function PlaceableClearAreas:onLoad(savegame) |
49 | local spec = self.spec_clearAreas |
50 | |
51 | spec.areas = {} |
52 | self.xmlFile:iterate("placeable.clearAreas.clearArea", function(_, key) |
53 | local area = {} |
54 | if self:loadClearArea(self.xmlFile, key, area) then |
55 | table.insert(spec.areas, area) |
56 | end |
57 | end) |
58 | |
59 | if not self.xmlFile:hasProperty("placeable.clearAreas") then |
60 | Logging.xmlWarning(self.xmlFile, "Missing clear areas") |
61 | end |
62 | end |
94 | function PlaceableClearAreas:onPostFinalizePlacement() |
95 | if self.isServer and not self.isLoadedFromSavegame then |
96 | local spec = self.spec_clearAreas |
97 | for _, area in pairs(spec.areas) do |
98 | local x,_,z = getWorldTranslation(area.start) |
99 | local x1,_,z1 = getWorldTranslation(area.width) |
100 | local x2,_,z2 = getWorldTranslation(area.height) |
101 | -- clear foliage |
102 | FSDensityMapUtil.removeFieldArea(x, z, x1, z1, x2, z2, false) |
103 | FSDensityMapUtil.removeWeedArea(x, z, x1, z1, x2, z2) |
104 | FSDensityMapUtil.removeStoneArea(x, z, x1, z1, x2, z2) |
105 | FSDensityMapUtil.eraseTireTrack(x, z, x1, z1, x2, z2) |
106 | FSDensityMapUtil.clearDecoArea(x, z, x1, z1, x2, z2) |
107 | -- clear tipAny |
108 | DensityMapHeightUtil.clearArea(x, z, x1, z1, x2, z2) |
109 | end |
110 | end |
111 | end |
37 | function PlaceableClearAreas.registerXMLPaths(schema, basePath) |
38 | schema:setXMLSpecializationType("ClearAreas") |
39 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".clearAreas.clearArea(?)#startNode", "Start node") |
40 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".clearAreas.clearArea(?)#widthNode", "Width node") |
41 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".clearAreas.clearArea(?)#heightNode", "Height node") |
42 | schema:setXMLSpecializationType() |
43 | end |