Skip to content

Commit 1d3a5fe

Browse files
committed
Code refactor and discharge code overhaul
1 parent 27a1f26 commit 1d3a5fe

42 files changed

Lines changed: 3054 additions & 3236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/PROCESSOR_BLEND.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
| type | string | Yes | | Processor type ```blend``` |
3030
| needsToBePoweredOn | boolean | No | ```true``` | Vehicle needs to be powered on |
3131
| needsToBeTurnedOn | boolean | No | ```true``` | Vehicle needs to be turned on (requires turnOnVehicle specialization) [^1] |
32+
| canToggleDischargeToGround | boolean | No | ```true``` | Whether player can toggle discharge to ground or not [^2] |
33+
| defaultCanDischargeToGround | boolean | No | ```false``` | Default value for discharging to ground setting [^2] |
34+
| canDischargeToGroundAnywhere | boolean | No | ```false``` | Bypass land permissions when discharging to ground [^2] |
35+
| canDischargeToAnyObject | boolean | No | ```false``` | Bypass vehicle permissions when discharging to object/vehicle [^2] |
3236

3337
[^1]: If the vehicle doesn't have a turn on function it will disregard this setting.
38+
[^2]: Only applies if custom discharge node(s) are used
3439

3540
## Configurations
3641

@@ -44,10 +49,10 @@ vehicle.materialProcessor.configurations.configuration(%)
4449
<materialProcessor type="blend">
4550
<configurations>
4651
<configuration name="$l10n_myConfigurationName" litersPerSecond="500">
47-
<output fillType="ASPHALT" fillUnitIndex="3">
48-
<input fillType="GRAVEL" fillUnitIndex="4" ratio="0.5" />
49-
<input fillType="DIRT" fillUnitIndex="5" ratio="0.4" />
50-
<input fillType="MIXTURE" fillUnitIndex="6" ratio="0.1" />
52+
<output fillType="ASPHALT" fillUnit="3">
53+
<input fillType="GRAVEL" fillUnit="4" ratio="0.5" />
54+
<input fillType="DIRT" fillUnit="5" ratio="0.4" />
55+
<input fillType="MIXTURE" fillUnit="6" ratio="0.1" />
5156
</output>
5257
</configuration>
5358

@@ -76,9 +81,9 @@ vehicle.materialProcessor.configurations.configuration(%).output
7681
| Name | Type | Required | Default | Description |
7782
|---------------|--------|----------|-------------|------------------------------|
7883
| fillType | string | Yes | | Name of filltype used for output |
79-
| fillUnitIndex | int | Yes | | Output vehicle fillUnitIndex |
80-
| hudNode | node | No | | Set custom node for HUD display position |
81-
84+
| fillUnit | int | Yes | | Output vehicle fillUnitIndex |
85+
| displayNode | node | No | | Set custom node for HUD display position |
86+
| displayNodeOffsetY | float | No | | Y offset position for HUD display |
8287

8388
### Inputs
8489

@@ -92,8 +97,7 @@ vehicle.materialProcessor.configurations.configuration(%).output.input(%)
9297
|---------------|---------|----------|---------|------------------------------|
9398
| ratio | float | Yes | | Ratio of input to output (50% = 0.5) |
9499
| fillType | string | Yes | | Name of filltype used for input |
95-
| fillUnitIndex | int | Yes | | Input vehicle fillUnitIndex |
96-
| hudNode | node | No | | Set custom node for HUD display position |
97-
| hidden | boolean | No | ```false``` | Hide input from HUD and GUI |
98-
99-
NOTE: It's important to make sure that all input ratios adds up to ```1.0```.
100+
| fillUnit | int | Yes | | Input vehicle fillUnitIndex |
101+
| displayNode | node | No | | Set custom node for HUD display position |
102+
| displayNodeOffsetY | float | No | | Y offset position for HUD display |
103+
| visible | boolean | No | ```true``` | Input visibility in HUD and GUI |

docs/PROCESSOR_SPLIT.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
| canToggleDischargeToGround | boolean | No | ```true``` | Whether player can toggle discharge to ground or not |
3838
| defaultCanDischargeToGround | boolean | No | ```false``` | Default value for discharging to ground setting |
3939
| canDischargeToGroundAnywhere | boolean | No | ```false``` | Bypass land permissions when discharging to ground |
40-
| canDischargeToAnyObject | boolean | No | ```false``` | Bypass vehicle permissions when discharging to object |
40+
| canDischargeToAnyObject | boolean | No | ```false``` | Bypass vehicle permissions when discharging to object/vehicle |
4141

4242
[^1]: If the vehicle doesn't have a turn on function it will disregard this setting.
4343

@@ -53,16 +53,22 @@ vehicle.materialProcessor.configurations.configuration(%)
5353
<materialProcessor type="split">
5454
<configurations>
5555
<configuration name="$l10n_myConfigurationName" litersPerSecond="500">
56-
<input fillType="DIRT" fillUnitIndex="3">
57-
<output fillType="GRAVEL" fillUnitIndex="4" ratio="0.3" />
58-
<output fillType="SAND" fillUnitIndex="5" ratio="0.7" />
56+
<input fillType="DIRT" fillUnit="3">
57+
<output fillType="GRAVEL" fillUnit="4" ratio="0.3" />
58+
<output fillType="SAND" fillUnit="5" ratio="0.7" />
5959
</input>
6060
</configuration>
6161

6262
<configuration name="Filter gravel" litersPerSecond="800">
63-
<input fillType="GRAVEL" fillUnitIndex="3">
64-
<output fillType="SAND" fillUnitIndex="4" ratio="0.1" />
65-
<output fillType="STONE" fillUnitIndex="5" ratio="0.9" />
63+
<input fillType="GRAVEL" fillUnit="3">
64+
<output fillType="SAND" fillUnit="4" ratio="0.1" />
65+
<output fillType="STONE" fillUnit="5" ratio="0.9" />
66+
</input>
67+
</configuration>
68+
69+
<configuration name="Screen sand" litersPerSecond="800">
70+
<input fillType="GRAVEL" fillUnit="3">
71+
<output fillType="SAND" fillUnit="4" ratio="0.1" />
6672
</input>
6773
</configuration>
6874
</configurations>
@@ -90,7 +96,8 @@ vehicle.materialProcessor.configurations.configuration(%).input
9096
|---------------|--------|----------|---------|------------------------------|
9197
| fillType | string | Yes | | Name of filltype used for input |
9298
| fillUnitIndex | int | Yes | | Input vehicle fillUnitIndex |
93-
| hudNode | node | No | | Set custom node for HUD display position |
99+
| displayNode | node | No | | Set custom node for HUD display position |
100+
| displayNodeOffsetY | float | No | | Y offset position for HUD display |
94101

95102
### Outputs
96103

@@ -104,14 +111,12 @@ vehicle.materialProcessor.configurations.configuration(%).input.output(%)
104111
|---------------|---------|----------|---------|------------------------------|
105112
| ratio | float | Yes | | Ratio of output to input (50% = 0.5) |
106113
| fillType | string | Yes | | Name of filltype used for output |
107-
| fillUnitIndex | int | Yes | | Output vehicle fillUnitIndex |
108-
| hudNode | node | No | | Set custom node for HUD display position |
109-
| hidden | boolean | No | ```false``` | Hide output from HUD and GUI |
110-
| discard | boolean| No | ```false``` | Set to true to discard output material instead of adding to fillUnit |
114+
| fillUnit | int | Yes | | Output vehicle fillUnitIndex |
115+
| displayNode | node | No | | Set custom node for HUD display position |
116+
| displayNodeOffsetY | float | No | | Y offset position for HUD display |
117+
| visible | boolean | No | ```true``` | Output visibility in HUD and GUI |
111118

112-
NOTE: It's important to make sure that all output ratios adds up to ```1.0```.
113-
114-
Also remember to add corresponding fillUnit [discharge node](#discharge-nodes) entries if you want to enable multiple discharge nodes to function simultaneously.
119+
Remember to add corresponding fillUnit [discharge node](#discharge-nodes) entries if you want to enable multiple discharge nodes to function simultaneously.
115120

116121

117122
## Discharge nodes
@@ -129,11 +134,12 @@ This element provides support for the same child elements as base game discharge
129134
- activationTrigger
130135
- distanceObjectChanges
131136
- stateObjectChanges
132-
- nodeActiveObjectChanges
133137
- effects
134138
- dischargeSound
135139
- dischargeStateSound
136140
- animationNodes
141+
- effectAnimationNodes
142+
- animation
137143

138144

139145
For more details on these look at the official documentation files for Vehicle.
@@ -146,12 +152,14 @@ For more details on these look at the official documentation files for Vehicle.
146152
| node | node | Yes | | Discharge node index path |
147153
| emptySpeed | int | No | ```250``` | Empty speed in liters/second |
148154
| stopDischargeIfNotPossible | boolean | No | ```true``` | Stop discharge if not possible |
155+
| allowDischargeWhenInactive | boolean | No | ```false``` | Allow discharging even if discharge node is not used by current configuration |
149156
| unloadInfoIndex | int | No | ```1``` | Unload info index |
150157
| effectTurnOffThreshold | float | No | ```0.25``` | After this time has passed and nothing has been processed the effects are turned off |
151158
| maxDistance | float | No | ```10``` | Max discharge distance |
152159
| soundNode | node | No | | Sound node index path |
153160
| playSound | boolean | No | ```true``` | Whether to play sounds |
154-
161+
| canFillOwnVehicle | boolean | No | ```false``` | Discharge node can fill other fill units of the vehicle itself |
162+
| toolType | string | No | ```dischargeable``` | Tool type |
155163

156164
### Example
157165
```xml

docs/example_blendProcessor.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
>
77
<configurations>
88
<configuration name="Asphalt" litersPerSecond="500">
9-
<output fillType="ASPHALT" fillUnitIndex="3">
10-
<input fillType="GRAVEL" fillUnitIndex="4" ratio="0.55" />
11-
<input fillType="SAND" fillUnitIndex="5" ratio="0.35" />
12-
<input fillType="BINDER" fillUnitIndex="6" ratio="0.1" />
9+
<output fillType="ASPHALT" fillUnit="3">
10+
<input fillType="GRAVEL" fillUnit="4" ratio="0.55" />
11+
<input fillType="SAND" fillUnit="5" ratio="0.35" />
12+
<input fillType="BINDER" fillUnit="6" ratio="0.1" />
1313
</output>
1414
</configuration>
1515
</configurations>
16+
17+
<!-- Optional; enables support for multiple discharge nodes -->
18+
<dischargeNodes>
19+
<!-- Discharge nodes .. -->
20+
<node />
21+
</dischargeNodes>
1622
</materialProcessor>
1723
</vehicle>

docs/example_splitProcessor.xml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@
1414
<configurations>
1515
<configuration name="Crush stones" litersPerSecond="500">
1616
<!-- Required-->
17-
<input fillType="STONES" fillUnitIndex="3">
18-
<!-- If ratio doesn't add up to 1.0 exactly you may encounter issues -->
19-
<output fillType="GRAVEL" fillUnitIndex="4" ratio="0.35" />
20-
<output fillType="RUBBLE" fillUnitIndex="5" ratio="0.65" />
17+
<input fillType="STONES" fillUnit="3">
18+
<output fillType="GRAVEL" fillUnit="4" ratio="0.35" />
19+
<output fillType="RUBBLE" fillUnit="5" ratio="0.65" />
2120
</input>
2221
</configuration>
2322
<configuration name="Filter gravel" litersPerSecond="800">
24-
<input fillType="GRAVEL" fillUnitIndex="3">
25-
<output fillType="DIRT" fillUnitIndex="4" ratio="0.25" />
26-
<output fillType="SAND" fillUnitIndex="5" ratio="0.7" />
27-
<output fillType="STONES" fillUnitIndex="6" ratio="0.05" />
23+
<input fillType="GRAVEL" fillUnit="3">
24+
<output fillType="DIRT" fillUnit="4" ratio="0.25" />
25+
<output fillType="SAND" fillUnit="5" ratio="0.7" />
26+
<output fillType="STONES" fillUnit="6" ratio="0.05" />
2827
</input>
2928
</configuration>
3029
</configurations>
3130

3231
<!-- Optional; enables support for multiple discharge nodes -->
3332
<dischargeNodes>
3433
<!-- Discharge nodes .. -->
35-
<!-- 1 entry for each output used -->
3634
<node />
3735
</dischargeNodes>
3836
</materialProcessor>

scripts/Configuration.lua

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---@class Configuration
2+
---@field processor Processor
3+
---@field index number
4+
---
5+
---@field displayName string
6+
---@field litersPerSecond number
7+
---@field litersPerMs number
8+
---@field fillUnitToConfigurationUnit table<number, ConfigurationUnit>
9+
Configuration = {}
10+
11+
---@param schema XMLSchema
12+
---@param key string
13+
function Configuration.registerXMLPaths(schema, key)
14+
schema:register(XMLValueType.L10N_STRING, key .. '#name', 'Name to display in GUI')
15+
schema:register(XMLValueType.INT, key .. '#litersPerSecond', 'Liters processed per second', 400, true)
16+
17+
BlendConfiguration.registerXMLPaths(schema, key)
18+
SplitConfiguration.registerXMLPaths(schema, key)
19+
end
20+
21+
---@param index number
22+
---@param processor Processor
23+
---@param customMt table
24+
---@return Configuration
25+
---@nodiscard
26+
function Configuration.new(index, processor, customMt)
27+
---@type Configuration
28+
local self = setmetatable({}, customMt)
29+
30+
self.index = index
31+
self.processor = processor
32+
33+
self.displayName = string.format('Configuration #%i', index)
34+
35+
self.litersPerSecond = 400
36+
self.litersPerMs = self.litersPerSecond / 1000
37+
38+
self.fillUnitToConfigurationUnit = {}
39+
40+
return self
41+
end
42+
43+
---@param xmlFile XMLFile
44+
---@param key string
45+
function Configuration:load(xmlFile, key)
46+
local displayName = xmlFile:getValue(key .. '#name', nil, self.processor.vehicle.customEnvironment)
47+
48+
if displayName ~= nil then
49+
self.displayName = displayName
50+
end
51+
52+
local litersPerSecond = xmlFile:getValue(key .. '#litersPerSecond')
53+
54+
if litersPerSecond == nil then
55+
Logging.xmlWarning(xmlFile, 'Missing "litersPerSecond" in configuration, using default (%i): %s', self.litersPerSecond, key .. '#litersPerSecond')
56+
else
57+
self.litersPerSecond = litersPerSecond
58+
self.litersPerMs = self.litersPerSecond / 1000
59+
end
60+
end
61+
62+
function Configuration:activate()
63+
self:getUnit():activate()
64+
65+
for _, unit in ipairs(self:getUnits()) do
66+
unit:activate()
67+
end
68+
end
69+
70+
function Configuration:deactivate()
71+
self:getUnit():deactivate()
72+
73+
for _, unit in ipairs(self:getUnits()) do
74+
unit:deactivate()
75+
end
76+
end
77+
78+
---@return ConfigurationUnit
79+
---@nodiscard
80+
function Configuration:getUnit()
81+
-- void
82+
---@diagnostic disable-next-line: missing-return
83+
end
84+
85+
---@return string
86+
---@nodiscard
87+
function Configuration:getUnitTitle()
88+
-- void
89+
---@diagnostic disable-next-line: missing-return
90+
end
91+
92+
---@return string
93+
---@nodiscard
94+
function Configuration:getUnitTypeName()
95+
-- void
96+
---@diagnostic disable-next-line: missing-return
97+
end
98+
99+
---@return ConfigurationUnit[]
100+
---@nodiscard
101+
function Configuration:getUnits()
102+
-- void
103+
---@diagnostic disable-next-line: missing-return
104+
end
105+
106+
---@return string
107+
---@nodiscard
108+
function Configuration:getUnitsTitle()
109+
-- void
110+
---@diagnostic disable-next-line: missing-return
111+
end
112+
113+
---@return string
114+
---@nodiscard
115+
function Configuration:getUnitsTypeName()
116+
-- void
117+
---@diagnostic disable-next-line: missing-return
118+
end

0 commit comments

Comments
 (0)