ZhooL / FS22_EnhancedVehicle

FS22. Farming Simulator 22. LS22. Landwirtschafts Simulator 22. Track assistant, parking brake, differential locks, wheel drive modes and better hydraulics controls for your vehicle. Shows more vehicle details on HUD.
222 stars 41 forks source link

Add fuel usage in l/ha #106

Closed yumi-modding closed 2 years ago

yumi-modding commented 2 years ago

Hello

From what I can see from farmers on YouTube, fuel usage is often displayed in l/ha in GPS monitor when working so you can know how much fuel you would use depending on different implement and in regard of your current working speed. I've looked at your code and started to implement this functionality. Would you like me to propose a PR for this ?

Yumi

ZhooL commented 2 years ago

It's not planned to implement additional features.

yumi-modding commented 2 years ago

Thanks @ZhooL for your feedback. In case someone wants to use this feature, here is the patch


$ git diff ui/FS22_EnhancedVehicle_HUD.lua
diff --git a/ui/FS22_EnhancedVehicle_HUD.lua b/ui/FS22_EnhancedVehicle_HUD.lua
index f2c15ab..0728937 100644
--- a/ui/FS22_EnhancedVehicle_HUD.lua
+++ b/ui/FS22_EnhancedVehicle_HUD.lua
@@ -976,6 +976,18 @@ function FS22_EnhancedVehicle_HUD:drawHUD()
         table.insert(fuel_txt, { string.format("%.1f kW/h", self.vehicle.spec_motorized.lastFuelUsage), 5 })
       else
         table.insert(fuel_txt, { string.format("%.1f l/h", self.vehicle.spec_motorized.lastFuelUsage), 5 })
+        if self.vehicle.vData.impl.workWidth and self.vehicle.vData.impl.workWidth > 0 then
+          local workWidth = self.vehicle.vData.impl.workWidth
+          local lastSpeed = self.vehicle:getLastSpeed()
+          local perf = lastSpeed * workWidth * 0.1
+          local result = self.vehicle.spec_motorized.lastFuelUsage / perf
+          -- lastFuelUsage: l/h
+          -- perf: ha/h = speed (m/h) * workWidth (m) * 0.0001
+          -- result: l/ha = lastFuelUsage / perf
+          -- print(string.format("workWidth: %.1f - lastSpeed: %.2f - perf: %.2f - result: %.26f", workWidth, lastSpeed, perf, result))
+          table.insert(fuel_txt, { string.format("%.1f l/ha", result), 6  })
+        end
       end
     end