├── FS22_realismAddon_fillables.zip ├── FS22_realismAddon_fillables ├── store.dds ├── modDesc.xml └── realismAddon_fillables.lua └── README.md /FS22_realismAddon_fillables.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelleicher/FS22_realismAddon_fillables/HEAD/FS22_realismAddon_fillables.zip -------------------------------------------------------------------------------- /FS22_realismAddon_fillables/store.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelleicher/FS22_realismAddon_fillables/HEAD/FS22_realismAddon_fillables/store.dds -------------------------------------------------------------------------------- /FS22_realismAddon_fillables/modDesc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | modelleicher (Farming Agency) 4 | 0.3.0.6 5 | 6 | <de>RealismAddon: Fillables</de> 7 | <en>RealismAddon: Fillables</en> 8 | 9 | 10 | 11 | 14 | 15 | 16 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | store.dds 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Kapazität-Überladen: an/aus schaltenCapacity-Overload: toggle on/off 49 | Kapazität-Überladen: anCapacity-Overload: on 50 | Kapazität-Überladen: ausCapactiy-Overload: off 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FS22_realismAddon_fillables 2 | This Script is made to enhance realism on fillable vehicles. It consists of mainly two things. 3 | 1. With default FS22, all fillTypes have real mass (and not half of real as in previous FS versions) 4 | If you play with the trailer fill limit enabled it allows you to only fill trailers until the max allowed weight of that trailer is reached through the amount of the particular fillType. 5 | If you play without the trailer fill limit enabled you can fill trailers up to 100% no matter what, BUT it will never weight more than max allowed weight. This means that the additional mass that would make the trailer heavier is discarded. 6 | This way it enables for unrealistically high capacities and casual players to not worry about having enough horsepower to pull a trailer. But for realism players this isn't enough. 7 | So this mod changes that. With trailer fill limit disabled you can load past the max allowed weight and the mass will be added. Also if you have the trailer selected it will show the % of overload below the fillLevel bar. 8 | In addition to that, if you have the trailer overloaded it will amount more damage when driving. The faster you drive the more damage amounts (speed^2) so if you need to overload your trailer, drive slowly unless you want to repair it often. 9 | 10 | 2. The second feature of this script is to not have a rigid capacity limit. You can fill trailers past 100%, BUT the further above 100% you fill the more of the fill gets "spilled" e.g. lost. 11 | This is simply because IRL you don't have any rigid limits either. If you have 150l left in your combine you don't need another trailer for that, or if you're full just a few meters away from the field ending you don't need to unload first. 12 | The loss is 0% at 100% capacity and 100% at 130% capacity but the actual loss amount is also a bit random up to 20% more than the mathematical loss, so as soon as 100% capacity are reached you can lose up to 20% of each further filling 13 | You can toggle this feature on/off on each vehicle by the additonal input-binding (needs to be mapped first, is not mapped by default) 14 | It is automatically on by default but for playing with Courseplay or AutoDrive it needs to be toggled off otherwise the helper will fill trailers up to 130% accumulating a lot of loss. 15 | 16 | # Credits 17 | - Modelleicher 18 | 19 | # Changelog: 20 | 21 | 22 | ###### V 0.3.0.5 23 | - fixed wheels-mass being added twice 24 | 25 | ###### V 0.3.0.4 26 | - fixed wrong capacity with excluded fillTypes in Multiplayer (water etc.) 27 | - deactivated automatic turn-off in forageWagons at 100% (careful, you have to turn off the wagon yourself otherwise it will load to 129% with a lot of loss) 28 | - fixed loss-calculation to have less loss at few % over 100, maximum loss at 130% is not 100% anymore either - random component on each level 29 | 30 | ###### V 0.3.0.3 31 | - added spec_baler to exclude List to stop Biobaler from overloading 32 | ###### V 0.3.0.2 33 | - Fixed last Multiplayer Issues, should now no longer be any issues in Multiplayer 34 | - added Input to disable filling above 100% on each vehicle individually (to deactivate it when playing with AutoDrive/Courseplay so they don't keep filling to 130%) 35 | ###### V 0.3.0.1 36 | - Fixed MixerWagons not working correctly in Multiplayer 37 | ###### V 0.3.0.0 38 | - Initial Github Release for FS22, 12th of Mai 2022 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /FS22_realismAddon_fillables/realismAddon_fillables.lua: -------------------------------------------------------------------------------- 1 | -- by modelleicher ( Farming Agency ) 2 | 3 | -- This Script is made to enhance realism on fillable vehicles. It consists of mainly two things. 4 | -- 1. With default FS22, all fillTypes have real mass (and not half of real as in previous FS versions) 5 | -- If you play with the trailer fill limit enabled it allows you to only fill trailers until the max allowed weight of that trailer is reached through the amount of the particular fillType. 6 | -- If you play without the trailer fill limit enabled you can fill trailers up to 100% no matter what, BUT it will never weight more than max allowed weight. This means that the additional mass that would make the trailer heavier is discarded. 7 | -- This way it enables for unrealistically high capacities and casual players to not worry about having enough horsepower to pull a trailer. But for realism players this isn't enough. 8 | -- So this mod changes that. With trailer fill limit disabled you can load past the max allowed weight and the mass will be added. Also if you have the trailer selected it will show the % of overload below the fillLevel bar. 9 | -- In addition to that, if you have the trailer overloaded it will amount more damage when driving. The faster you drive the more damage amounts (speed^2) so if you need to overload your trailer, drive slowly unless you want to repair it often. 10 | -- 11 | -- 2. The second feature of this script is to not have a rigid capacity limit. You can fill trailers past 100%, BUT the further above 100% you fill the more of the fill gets "spilled" e.g. lost. 12 | -- This is simply because IRL you don't have any rigid limits either. If you have 150l left in your combine you don't need another trailer for that, or if you're full just a few meters away from the field ending you don't need to unload first. 13 | -- The loss is 0% at 100% capacity and 100% at 130% capacity but the actual loss amount is also a bit random up to 20% more than the mathematical loss, so as soon as 100% capacity are reached you can lose up to 20% of each further filling 14 | 15 | realismAddon_fillables = {}; 16 | 17 | -- Multiplayer for the max amount a fillUnit can be overfilled, 1.5 = 150%, at max there will be 100% loss so this value is never actually reached when playing realistically 18 | realismAddon_fillables.capacityMultiplier = 1.3 19 | 20 | -- list of specs that need to be included in order to change the capacity limit 21 | realismAddon_fillables.includeSpecList = {"spec_combine", "spec_trailer"} 22 | -- list of specs that if included disable the capacity limit 23 | realismAddon_fillables.excludeSpecList = {"spec_mixerWagon", "spec_baler" } 24 | -- list of fillTypes that are excluded from the capacity limit change 25 | realismAddon_fillables.excludeFillTypesList = {"unknown", "cotton", "diesel", "water", "liquidManure", "liquidFertilizer", "milk", "def", "herbicide", "digestate", "SUNFLOWER_OIL", "CANOLA_OIL", "OLIVE_OIL", "CHOCOLATE", "BOARDS", "FURNITURE", "EGG", "TOMATO", "LETTUCE", "ELECTRICCHARGE", "METHANE", "WOOL", "TREESAPLINGS" } 26 | 27 | 28 | 29 | -- Input stuff for turning the feature off on particular vehicles for compatability with Courseplay/AutoDrive and so on 30 | ------------------------------------------------------------------------------------------------------------------------ 31 | -- onRegister actionEvent for FillUnit 32 | function realismAddon_fillables.onRegisterActionEvents(self, isActiveForInput, isActiveForInputIgnoreSelection) 33 | if self.isClient then 34 | local spec = self.spec_fillUnit 35 | 36 | if isActiveForInputIgnoreSelection then 37 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.REALISM_ADDON_FILLABLES_LOCALONOFF , self, FillUnit.RAFtoggleOnOffLocally, false, true, false, true, nil) 38 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) 39 | 40 | if spec.realismAddon_fillables_active then 41 | g_inputBinding:setActionEventText(actionEventId, g_i18n:getText("action_REALISM_ADDON_FILLABLES_LOCALON")) 42 | else 43 | g_inputBinding:setActionEventText(actionEventId, g_i18n:getText("action_REALISM_ADDON_FILLABLES_LOCALOFF")) 44 | end 45 | end 46 | end 47 | end 48 | FillUnit.onRegisterActionEvents = Utils.appendedFunction(FillUnit.onRegisterActionEvents, realismAddon_fillables.onRegisterActionEvents) 49 | 50 | -- add toggleOnOffLocally function 51 | function realismAddon_fillables.registerFunctions(vehicleType) 52 | SpecializationUtil.registerFunction(vehicleType, "RAFtoggleOnOffLocally", FillUnit.RAFtoggleOnOffLocally) 53 | end 54 | FillUnit.registerFunctions = Utils.appendedFunction(FillUnit.registerFunctions, realismAddon_fillables.registerFunctions) 55 | 56 | -- register realismAddon_fillables_active variable in onLoad 57 | function realismAddon_fillables.onLoad(self, superFunc, savegame) 58 | local returnValue = superFunc(self, savegame) 59 | 60 | local spec = self.spec_fillUnit 61 | spec.realismAddon_fillables_active = true 62 | 63 | return returnValue 64 | end 65 | FillUnit.onLoad = Utils.overwrittenFunction(FillUnit.onLoad, realismAddon_fillables.onLoad) 66 | 67 | -- toggle func is also the inputEvent func at the same time 68 | function FillUnit.RAFtoggleOnOffLocally(self, actionName, inputValue, callbackState, isAnalog, value, value2, value3, state, noEventSend) 69 | local spec = self.spec_fillUnit 70 | 71 | 72 | 73 | if state ~= nil then 74 | spec.realismAddon_fillables_active = state 75 | else 76 | spec.realismAddon_fillables_active = not spec.realismAddon_fillables_active 77 | end 78 | 79 | -- call event 80 | realismAddon_fillables_toggleOnOffEvent.sendEvent(self, state, noEventSend) 81 | 82 | if spec.actionEvents ~= nil and spec.actionEvents[InputAction.REALISM_ADDON_FILLABLES_LOCALONOFF] ~= nil then 83 | if spec.realismAddon_fillables_active then 84 | g_inputBinding:setActionEventText(spec.actionEvents[InputAction.REALISM_ADDON_FILLABLES_LOCALONOFF].actionEventId, g_i18n:getText("action_REALISM_ADDON_FILLABLES_LOCALON")) 85 | else 86 | g_inputBinding:setActionEventText(spec.actionEvents[InputAction.REALISM_ADDON_FILLABLES_LOCALONOFF].actionEventId, g_i18n:getText("action_REALISM_ADDON_FILLABLES_LOCALOFF")) 87 | end 88 | end 89 | end 90 | 91 | -- onReadStream and onWriteStream 92 | function realismAddon_fillables.onReadStream(self, streamId, connection) 93 | local spec = self.spec_fillUnit 94 | if spec.realismAddon_fillables_active ~= nil then 95 | local realismAddon_fillables_active = streamReadBool(streamId) 96 | if realismAddon_fillables_active ~= nil then 97 | self:RAFtoggleOnOffLocally(nil, nil, nil, nil, nil, nil, nil, realismAddon_fillables_active, true) 98 | end 99 | end 100 | end 101 | FillUnit.onReadStream = Utils.appendedFunction(FillUnit.onReadStream, realismAddon_fillables.onReadStream) 102 | 103 | function realismAddon_fillables.onWriteStream(self, streamId, connection) 104 | local spec = self.spec_fillUnit 105 | if spec.realismAddon_fillables_active ~= nil then 106 | streamWriteBool(streamId, spec.realismAddon_fillables_active) 107 | end 108 | end 109 | FillUnit.onWriteStream = Utils.appendedFunction(FillUnit.onWriteStream, realismAddon_fillables.onWriteStream) 110 | 111 | 112 | -- Event for toggle on off locally per vehicle 113 | realismAddon_fillables_toggleOnOffEvent = {} 114 | local realismAddon_fillables_toggleOnOffEvent_mt = Class(realismAddon_fillables_toggleOnOffEvent, Event) 115 | 116 | InitEventClass(realismAddon_fillables_toggleOnOffEvent, "realismAddon_fillables_toggleOnOffEvent") 117 | 118 | function realismAddon_fillables_toggleOnOffEvent.emptyNew() 119 | local self = Event.new(realismAddon_fillables_toggleOnOffEvent_mt) 120 | self.className = "realismAddon_fillables_toggleOnOffEvent"; 121 | return self 122 | end 123 | 124 | function realismAddon_fillables_toggleOnOffEvent.new(vehicle, state) 125 | local self = realismAddon_fillables_toggleOnOffEvent.emptyNew() 126 | self.vehicle = vehicle 127 | self.state = state 128 | 129 | return self 130 | end 131 | 132 | function realismAddon_fillables_toggleOnOffEvent:readStream(streamId, connection) 133 | self.vehicle = NetworkUtil.readNodeObject(streamId) 134 | self.state = streamReadBool(streamId) 135 | 136 | self:run(connection) 137 | end 138 | 139 | function realismAddon_fillables_toggleOnOffEvent:writeStream(streamId, connection) 140 | NetworkUtil.writeNodeObject(streamId, self.vehicle) 141 | streamWriteBool(streamId, self.state) 142 | end 143 | 144 | function realismAddon_fillables_toggleOnOffEvent:run(connection) 145 | if self.vehicle ~= nil and self.vehicle:getIsSynchronized() then 146 | self.vehicle:RAFtoggleOnOffLocally(nil, nil, nil, nil, nil, nil, nil, self.state, true) 147 | end 148 | 149 | if not connection:getIsServer() then 150 | g_server:broadcastEvent(realismAddon_fillables_toggleOnOffEvent.new(self.vehicle, self.state), nil, connection, self.vehicle) 151 | end 152 | end 153 | 154 | function realismAddon_fillables_toggleOnOffEvent.sendEvent(vehicle, state, noEventSend) 155 | if (noEventSend == nil or noEventSend == false) then 156 | if g_server ~= nil then 157 | g_server:broadcastEvent(realismAddon_fillables_toggleOnOffEvent.new(vehicle, state), nil, nil, vehicle) 158 | else 159 | g_client:getServerConnection():sendEvent(realismAddon_fillables_toggleOnOffEvent.new(vehicle, state)) 160 | end 161 | end 162 | end 163 | -- Input Stuff End 164 | ------------------- 165 | 166 | function realismAddon_fillables.checkIncludeExcludeSpecs(self) 167 | local includes = false 168 | for _, specname in pairs(realismAddon_fillables.includeSpecList) do 169 | if self[specname] ~= nil then 170 | includes = true 171 | break 172 | end 173 | end 174 | 175 | local excludes = true 176 | for _, specname in pairs(realismAddon_fillables.excludeSpecList) do 177 | if self[specname] ~= nil then 178 | excludes = false 179 | break 180 | end 181 | end 182 | 183 | return includes, excludes 184 | end 185 | 186 | function realismAddon_fillables.checkExcludeFillType(fillUnit) 187 | 188 | for _, fillTypeName in pairs(realismAddon_fillables.excludeFillTypesList) do 189 | 190 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName) 191 | 192 | if fillUnit.fillType == fillTypeIndex then 193 | return false 194 | end 195 | end 196 | return true 197 | end 198 | 199 | function realismAddon_fillables.fillForageWagon(self, superFunc) 200 | 201 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 202 | if includes and excludes and self.spec_fillUnit.realismAddon_fillables_active then 203 | local spec = self.spec_forageWagon 204 | 205 | local loadInfo = self:getFillVolumeLoadInfo(spec.loadInfoIndex) 206 | local filledLiters = self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, spec.workAreaParameters.litersToFill, spec.lastFillType, ToolType.UNDEFINED, loadInfo) 207 | 208 | local fillUnit = self.spec_fillUnit.fillUnits[spec.fillUnitIndex] 209 | if fillUnit.fillLevel >= fillUnit.capacity * (realismAddon_fillables.capacityMultiplier - 0.01) then 210 | self:setIsTurnedOn(false) 211 | self:setPickupState(false) 212 | end 213 | 214 | spec.workAreaParameters.litersToFill = spec.workAreaParameters.litersToFill - filledLiters 215 | 216 | if spec.workAreaParameters.litersToFill < 0.01 then 217 | spec.workAreaParameters.litersToFill = 0 218 | end 219 | return true 220 | else 221 | return superFunc() 222 | end 223 | end 224 | ForageWagon.fillForageWagon = Utils.overwrittenFunction(ForageWagon.fillForageWagon, realismAddon_fillables.fillForageWagon) 225 | 226 | 227 | function realismAddon_fillables:addFillUnitFillLevel(superFunc, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) 228 | 229 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 230 | 231 | local spec = self.spec_fillUnit 232 | 233 | if includes and excludes and spec.realismAddon_fillables_active then 234 | 235 | local fillUnit = spec.fillUnits[fillUnitIndex] 236 | 237 | if fillUnit ~= nil and realismAddon_fillables.checkExcludeFillType(fillUnit) then 238 | 239 | -- backup original capacity 240 | local capacityOriginal = fillUnit.capacity 241 | 242 | -- capacity is temporarily raised by realismAddon_fillables.capacityMultiplier 243 | fillUnit.capacity = fillUnit.capacity * realismAddon_fillables.capacityMultiplier 244 | 245 | -- calculate the loss-amount 246 | -- it is 0% loss at 100% default capacity and 100% loss when reaching the new capacity 247 | -- the actual amount is also a bit random 248 | 249 | -- only do stuff if we add to the fillUnit, not remove 250 | if fillLevelDelta > 0 then 251 | local oldLevel = fillUnit.fillLevel 252 | 253 | -- only do stuff if we actually are at capacity or above 254 | if oldLevel > capacityOriginal then 255 | 256 | -- to make it easier, use oldLevel to calculate loss, not potential new level 257 | -- percent loss amount over / range 258 | local lossPercent = (oldLevel - capacityOriginal) / (fillUnit.capacity - capacityOriginal) 259 | 260 | -- random value between 0 and 1 261 | local randomValue = math.random() 262 | 263 | -- changed to lossPercent * randomValue 264 | lossPercent = math.min(1, lossPercent * randomValue) 265 | 266 | -- finally remove loss from delta (changed) 267 | fillLevelDelta = fillLevelDelta - (fillLevelDelta * lossPercent) 268 | end 269 | end 270 | 271 | -- call original function while capacity is temporarily raised and with loss-added delta 272 | local returnValue = superFunc(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) 273 | 274 | -- reset capacity 275 | fillUnit.capacity = capacityOriginal 276 | 277 | return returnValue 278 | else 279 | return superFunc(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) 280 | end 281 | else 282 | return superFunc(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) 283 | end 284 | 285 | end 286 | FillUnit.addFillUnitFillLevel = Utils.overwrittenFunction(FillUnit.addFillUnitFillLevel, realismAddon_fillables.addFillUnitFillLevel) 287 | 288 | -- getFillUnitAllowsFillType checks if fillLevel is below capacity for given fillType so we need to replace capacity temporarily there too 289 | function realismAddon_fillables:getFillUnitAllowsFillType(superFunc, fillUnitIndex, fillType) 290 | 291 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 292 | 293 | local spec = self.spec_fillUnit 294 | 295 | if includes and excludes and spec.realismAddon_fillables_active then 296 | 297 | local fillUnit = spec.fillUnits[fillUnitIndex] 298 | 299 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 300 | 301 | -- backup original capacity 302 | local capacityOriginal = fillUnit.capacity 303 | 304 | -- capacity is temporarily raised by realismAddon_fillables.capacityMultiplier 305 | fillUnit.capacity = fillUnit.capacity * realismAddon_fillables.capacityMultiplier 306 | 307 | -- call original function while capacity is temporarily raised 308 | local returnValue = superFunc(self, fillUnitIndex, fillType) 309 | 310 | -- reset capacity 311 | fillUnit.capacity = capacityOriginal 312 | 313 | return returnValue 314 | else 315 | return superFunc(self, fillUnitIndex, fillType) 316 | end 317 | else 318 | return superFunc(self, fillUnitIndex, fillType) 319 | end 320 | end 321 | FillUnit.getFillUnitAllowsFillType = Utils.overwrittenFunction(FillUnit.getFillUnitAllowsFillType, realismAddon_fillables.getFillUnitAllowsFillType) 322 | 323 | -- getFillUnitFreeCapacity returns the available free capacity so we need to overwrite this as well 324 | function realismAddon_fillables:getFillUnitFreeCapacity(superFunc, fillUnitIndex, fillTypeIndex, farmId) 325 | 326 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 327 | 328 | local spec = self.spec_fillUnit 329 | 330 | if includes and excludes and spec.realismAddon_fillables_active then 331 | 332 | local fillUnit = spec.fillUnits[fillUnitIndex] 333 | 334 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 335 | 336 | -- backup original capacity 337 | local capacityOriginal = fillUnit.capacity 338 | -- capacity is temporarily raised by realismAddon_fillables.capacityMultiplier 339 | fillUnit.capacity = fillUnit.capacity * realismAddon_fillables.capacityMultiplier 340 | 341 | -- call original function while capacity is temporarily raised 342 | local returnValue = superFunc(self, fillUnitIndex, fillTypeIndex, farmId) 343 | 344 | -- reset capacity 345 | fillUnit.capacity = capacityOriginal 346 | 347 | return returnValue 348 | else 349 | return superFunc(self, fillUnitIndex, fillTypeIndex, farmId) 350 | end 351 | else 352 | return superFunc(self, fillUnitIndex, fillTypeIndex, farmId) 353 | end 354 | end 355 | FillUnit.getFillUnitFreeCapacity = Utils.overwrittenFunction(FillUnit.getFillUnitFreeCapacity, realismAddon_fillables.getFillUnitFreeCapacity) 356 | 357 | function realismAddon_fillables.onReadUpdateStream(self, superFunc, streamId, timestamp, connection) 358 | 359 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 360 | 361 | local spec = self.spec_fillUnit 362 | 363 | 364 | if includes and excludes and spec.realismAddon_fillables_active then 365 | 366 | -- go through all fillUnits and set capacities if neccesary 367 | for i = 1, table.getn(spec.fillUnits) do 368 | local fillUnit = spec.fillUnits[i] 369 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 370 | -- backup original capacity 371 | fillUnit.capacityOriginal = fillUnit.capacity 372 | -- capacity is temporarily raised by realismAddon_fillables.capacityMultiplier 373 | fillUnit.capacity = fillUnit.capacity * realismAddon_fillables.capacityMultiplier 374 | end 375 | end 376 | 377 | 378 | -- call original function while capacity is temporarily raised 379 | local returnValue = superFunc(self, streamId, timestamp, connection) 380 | 381 | 382 | -- go through all fillUnits and reset capacities if neccesary 383 | for i = 1, table.getn(spec.fillUnits) do 384 | local fillUnit = spec.fillUnits[i] 385 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 386 | -- reset capacity back 387 | -- check if capacityOriginal backup exists first because if fillUnit fillType changed during call of the original function it might not have been affected by the capacity change this call 388 | if fillUnit.capacityOriginal ~= nil then 389 | fillUnit.capacity = fillUnit.capacityOriginal 390 | end 391 | end 392 | end 393 | 394 | 395 | return returnValue 396 | else 397 | return superFunc(self, streamId, timestamp, connection) 398 | end 399 | 400 | end 401 | FillUnit.onReadUpdateStream = Utils.overwrittenFunction(FillUnit.onReadUpdateStream, realismAddon_fillables.onReadUpdateStream) 402 | 403 | function realismAddon_fillables.onWriteUpdateStream(self, superFunc, streamId, connection, dirtyMask) 404 | local includes, excludes = realismAddon_fillables.checkIncludeExcludeSpecs(self) 405 | 406 | local spec = self.spec_fillUnit 407 | 408 | 409 | if includes and excludes and spec.realismAddon_fillables_active then 410 | 411 | -- go through all fillUnits and set capacities if neccesary 412 | for i = 1, table.getn(spec.fillUnits) do 413 | local fillUnit = spec.fillUnits[i] 414 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 415 | -- backup original capacity 416 | fillUnit.capacityOriginal = fillUnit.capacity 417 | -- capacity is temporarily raised by realismAddon_fillables.capacityMultiplier 418 | fillUnit.capacity = fillUnit.capacity * realismAddon_fillables.capacityMultiplier 419 | end 420 | end 421 | 422 | -- call original function while capacity is temporarily raised 423 | local returnValue = superFunc(self, streamId, connection, dirtyMask) 424 | 425 | -- go through all fillUnits and reset capacities if neccesary 426 | for i = 1, table.getn(spec.fillUnits) do 427 | local fillUnit = spec.fillUnits[i] 428 | if realismAddon_fillables.checkExcludeFillType(fillUnit) then 429 | -- reset capacity back 430 | fillUnit.capacity = fillUnit.capacityOriginal 431 | end 432 | end 433 | 434 | return returnValue 435 | else 436 | return superFunc(self, streamId, connection, dirtyMask) 437 | end 438 | end 439 | FillUnit.onWriteUpdateStream = Utils.overwrittenFunction(FillUnit.onWriteUpdateStream, realismAddon_fillables.onWriteUpdateStream) 440 | 441 | 442 | -- 443 | function realismAddon_fillables:onDrawFillUnit(superFunc, isActiveForInput, isActiveForInputIgnoreSelection) 444 | superFunc(self, isActiveForInput, isActiveForInputIgnoreSelection) 445 | 446 | if isActiveForInput then 447 | if self.overloadPercentage ~= nil and self.overloadPercentage > 0 then 448 | 449 | setTextAlignment(RenderText.ALIGN_LEFT) 450 | setTextBold(true) 451 | setTextColor(0.8, 0, 0, 1) 452 | renderText(0.725, 0.014, 0.014, tostring(self.overloadPercentage).."% overloaded") 453 | setTextColor(1, 1, 1, 1) 454 | renderText(0.724, 0.013, 0.014, tostring(self.overloadPercentage).."% overloaded") 455 | end 456 | end 457 | end 458 | FillUnit.onDraw = Utils.overwrittenFunction(FillUnit.onDraw, realismAddon_fillables.onDrawFillUnit) 459 | 460 | function realismAddon_fillables:onUpdateTickFillUnit(superFunc, dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) 461 | superFunc(self, dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) 462 | 463 | -- calculate added damage from overloading 464 | if self.overloadPercentage ~= nil and self.overloadPercentage > 0 and self:getLastSpeed() > 1 and self.addDamageAmount ~= nil then 465 | -- speed range from 0 to 80kph with FS vehicles 466 | local speedFactor = math.min(80, self:getLastSpeed()) / 80 -- range 0 to 1 467 | local overloadFactor = self.overloadPercentage / 100 -- range 0 to 1 whereas 1 = 100% overloading 468 | 469 | -- overloading itself shouldn't be as bad but adding speed to it makes it so much worse 470 | local damageFactor = self.overloadPercentage * (speedFactor ^ 2) -- at 25% overload, 0.4 damage at 10kph, 1.6 damage at 20kph, 6.25 damage at 40kph, 25 damage at 80kph 471 | 472 | local damageAdd = 0.0000001 * dt * damageFactor 473 | 474 | self:addDamageAmount(damageAdd) 475 | end 476 | end 477 | FillUnit.onUpdateTick = Utils.overwrittenFunction(FillUnit.onUpdateTick, realismAddon_fillables.onUpdateTickFillUnit) 478 | 479 | -- overwrite Vehicle.updateMass so mass is calculated differently, mass will not be limited by maxMass anymore 480 | function realismAddon_fillables.updateVehicleMass(self, superFunc) 481 | 482 | -- only run our func if fillUnit exists in this vehicle (maybe change to tipper or something like that if issues arise) 483 | if self.spec_fillUnit == nil then 484 | superFunc(self) 485 | end 486 | 487 | -- reset to 0 488 | self.serverMass = 0 489 | 490 | for _, component in ipairs(self.components) do 491 | 492 | -- why is defaultMass not set in load? 493 | if component.defaultMass == nil then 494 | if component.isDynamic then 495 | component.defaultMass = getMass(component.node) 496 | else 497 | component.defaultMass = 1 498 | end 499 | end 500 | 501 | -- get additionalMass from other specializations, this is first 502 | local additionalMass = self:getAdditionalComponentMass(component) 503 | 504 | -- set component mass, this needs to happen before the next step 505 | component.mass = component.defaultMass + additionalMass 506 | 507 | -- get component mass with wheels, the component.mass from above is already used 508 | --component.mass = self:getComponentMass(component) 509 | 510 | -- add to serverMass 511 | --self.serverMass = self.serverMass + component.mass 512 | self.serverMass = self.serverMass + self:getComponentMass(component) 513 | -- change mass calculation to not double the wheels fix 514 | 515 | -- calculate overload percentage 516 | self.overloadPercentage = 0 517 | if self.serverMass > self.maxComponentMass then 518 | self.overloadPercentage = math.floor(((self.serverMass / self.maxComponentMass) - 1) * 100) 519 | end 520 | 521 | -- if mass changed more than 2kg update 522 | if self.isServer and component.isDynamic and math.abs(component.lastMass - component.mass) > 0.02 then 523 | 524 | setMass(component.node, component.mass) 525 | 526 | component.lastMass = component.mass 527 | end 528 | 529 | end 530 | end 531 | Vehicle.updateMass = Utils.overwrittenFunction(Vehicle.updateMass, realismAddon_fillables.updateVehicleMass) 532 | 533 | -- overwrite Vehicle.getSpecValueAdditionalWeight function so it does show the possible load weight even with trailerFillLimit turned off 534 | function realismAddon_fillables.vehicleGetSpecValueAdditionalWeight(storeItem, superFunc, realItem, configurations, saleItem, returnValues, returnRange) 535 | 536 | if storeItem.specs.additionalWeight ~= nil then 537 | local baseWeight = Vehicle.getSpecValueWeight(storeItem, realItem, configurations, saleItem, true) 538 | 539 | if baseWeight ~= nil then 540 | local additionalWeight = storeItem.specs.additionalWeight - baseWeight 541 | 542 | if returnValues then 543 | return additionalWeight 544 | else 545 | return g_i18n:formatMass(additionalWeight) 546 | end 547 | end 548 | end 549 | 550 | return nil 551 | end 552 | Vehicle.getSpecValueAdditionalWeight = Utils.overwrittenFunction(Vehicle.getSpecValueAdditionalWeight, realismAddon_fillables.vehicleGetSpecValueAdditionalWeight) 553 | 554 | 555 | --------------------------------------------------------------------------------