97Lukas90

Untitled

Mar 10th, 2021 (edited)
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.35 KB | None | 0 0
  1. advancedCombine = {}
  2. --local modName = g_currentModName
  3. local modDirectory  = g_currentModDirectory
  4.  
  5. function advancedCombine.prerequisitesPresent(specializations)
  6.     return true
  7. end
  8.  
  9. function advancedCombine.registerEventListeners(vehicleType)
  10.     SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", advancedCombine)
  11.     SpecializationUtil.registerEventListener(vehicleType, "onLoad", advancedCombine)
  12.     SpecializationUtil.registerEventListener(vehicleType, "onUpdate", advancedCombine)
  13.     SpecializationUtil.registerEventListener(vehicleType, "onDraw", advancedCombine)
  14.     SpecializationUtil.registerEventListener(vehicleType, "onDelete", advancedCombine)
  15.    
  16.     advancedCombine.ModifierType = g_soundManager:registerModifierType("ROTOR_RPM", advancedCombine.getRotorRpm, advancedCombine.getMinRotorRpm, advancedCombine.getMaxRotorRpm)
  17.     advancedCombine.ModifierType2 = g_soundManager:registerModifierType("CAMERA_ROTATION", advancedCombine.getCameraRot, advancedCombine.getMinCamRot, advancedCombine.getMaxCamRot)
  18.     advancedCombine.ModifierType3 = g_soundManager:registerModifierType("CHOPPER_VOLUME", advancedCombine.getChopperVolume, advancedCombine.getMinChopperVolume, advancedCombine.getMaxChopperVolume)
  19. end
  20.  
  21. function advancedCombine.registerFunctions(vehicleType)
  22.     SpecializationUtil.registerFunction(vehicleType, "calculateSpill", advancedCombine.calculateSpill)
  23.     SpecializationUtil.registerFunction(vehicleType, "getCorrectGrainTypeSelection", advancedCombine.getCorrectGrainTypeSelection)
  24. end
  25.  
  26. --function advancedCombine.registerOverwrittenFunctions(vehicleType)
  27. --  SpecializationUtil.registerOverwrittenFunction(vehicleType, "getPtoRpm", advancedCombine.getPtoRpm)
  28. --end
  29.  
  30. function advancedCombine:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
  31.     if self.isClient then
  32.         local spec = self.spec_advancedCombine
  33.         spec.actionEvents = {}
  34.         self:clearActionEventsTable(spec.actionEvents)
  35.  
  36.         if self:getIsActiveForInput(true, true) then                                                        --- triggerUp, triggerDown, triggerAlways, startActive, callbackState
  37.             local _, actionShowHUDEventId = self:addActionEvent(spec.actionEvents, InputAction.SHOW_SPILL_HUD, self, advancedCombine.processActionEvent, false, true, false, true)
  38.             local _, actionToggleDisplayModeEventId = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_DISPLAY_MODE, self, advancedCombine.processActionEvent, false, true, false, true)
  39.             local _, actionChangeThresherRPMEventId = self:addActionEvent(spec.actionEvents, InputAction.AXIS_THRESHER_RPM, self, advancedCombine.actionEventThresherRPM, false, true, true, true)
  40.             local _, actionChangeConcaveEventId = self:addActionEvent(spec.actionEvents, InputAction.AXIS_CONCAVE, self, advancedCombine.actionEventConcave, false, true, false, true)
  41.             local _, actionChangeWindRPMEventId = self:addActionEvent(spec.actionEvents, InputAction.AXIS_WIND_RPM, self, advancedCombine.actionEventWindRPM, false, true, false, true)
  42.             local _, actionChangeSieveEventId = self:addActionEvent(spec.actionEvents, InputAction.AXIS_SIEVE, self, advancedCombine.actionEventSieve, false, true, false, true)
  43.            
  44.             spec.actionEventIds = {actionChangeThresherRPMEventId, actionChangeConcaveEventId, actionChangeWindRPMEventId, actionChangeSieveEventId}
  45.  
  46.             g_inputBinding:setActionEventTextPriority(actionShowHUDEventId, GS_PRIO_HIGH)
  47.             g_inputBinding:setActionEventTextVisibility(actionShowHUDEventId, true)
  48.            
  49.             g_inputBinding:setActionEventText(actionChangeThresherRPMEventId, g_i18n:getText("action_CHANGE_THRESHER_RPM"))
  50.             g_inputBinding:setActionEventText(actionChangeConcaveEventId, g_i18n:getText("action_CHANGE_CONCAVE"))
  51.             g_inputBinding:setActionEventText(actionChangeWindRPMEventId, g_i18n:getText("action_CHANGE_WIND_RPM"))
  52.             g_inputBinding:setActionEventText(actionChangeSieveEventId, g_i18n:getText("action_CHANGE_SIEVE"))
  53.             g_inputBinding:setActionEventTextPriority(actionChangeThresherRPMEventId, GS_PRIO_HIGH)
  54.             g_inputBinding:setActionEventTextPriority(actionChangeConcaveEventId, GS_PRIO_HIGH)
  55.             g_inputBinding:setActionEventTextPriority(actionChangeWindRPMEventId, GS_PRIO_HIGH)
  56.             g_inputBinding:setActionEventTextPriority(actionChangeSieveEventId, GS_PRIO_HIGH)
  57.            
  58.             for k,eventId in pairs(spec.actionEventIds) do
  59.                 g_inputBinding:setActionEventTextVisibility(eventId, false)
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65. function advancedCombine:onLoad(savegame)
  66.     self.spec_advancedCombine = {}
  67.     local spec = self.spec_advancedCombine
  68.    
  69.    
  70.     spec.grainTypeSwitch = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.advancedCombine.grainTypeSwitch#node"), self.i3dMappings)
  71.     spec.grainTypeSwitchRotation = {}
  72.     if spec.grainTypeSwitch ~= nil then
  73.         spec.grainTypeSwitchRotation[1], spec.grainTypeSwitchRotation[2], spec.grainTypeSwitchRotation[3] = getRotation(spec.grainTypeSwitch)
  74.     end
  75.    
  76.     spec.grainTypes = {}
  77.     spec.combineSettings = {}
  78.     spec.combineSettings.baseInfos = {}
  79.    
  80.     local settingsKey = "vehicle.advancedCombine.combineSettings"
  81.     local concaveMin = getXMLInt(self.xmlFile, settingsKey..".concave#min")
  82.     local concaveMax = getXMLInt(self.xmlFile, settingsKey..".concave#max")
  83.     local concaveChangeStep = Utils.getNoNil(getXMLInt(self.xmlFile, settingsKey..".concave#changeStep"), 1)
  84.     spec.combineSettings.baseInfos.concave = {min=concaveMin, max=concaveMax, changeStep=concaveChangeStep}
  85.    
  86.     local windMin = getXMLInt(self.xmlFile, settingsKey..".wind#min")
  87.     local windMax = getXMLInt(self.xmlFile, settingsKey..".wind#max")
  88.     local windChangeStep = Utils.getNoNil(getXMLInt(self.xmlFile, settingsKey..".wind#changeStep"), 1)
  89.     spec.combineSettings.baseInfos.wind = {min=windMin, max=windMax, changeStep=windChangeStep}
  90.    
  91.     local sieveMin = getXMLInt(self.xmlFile, settingsKey..".sieve#min")
  92.     local sieveMax = getXMLInt(self.xmlFile, settingsKey..".sieve#max")
  93.     local sieveChangeStep = Utils.getNoNil(getXMLInt(self.xmlFile, settingsKey..".sieve#changeStep"), 1)
  94.     spec.combineSettings.baseInfos.sieve = {min=sieveMin, max=sieveMax, changeStep=sieveChangeStep}
  95.    
  96.     local drumMin = getXMLInt(self.xmlFile, settingsKey..".threshingDrum#min")
  97.     local drumMax = getXMLInt(self.xmlFile, settingsKey..".threshingDrum#max")
  98.     local drumChangeSpeed = Utils.getNoNil(getXMLInt(self.xmlFile, settingsKey..".threshingDrum#changeSpeed"), 1)
  99.     spec.combineSettings.baseInfos.threshingDrum = {min=drumMin, max=drumMax, changeSpeed=drumChangeSpeed}
  100.    
  101.     local i = 0
  102.     while true do
  103.         local key = string.format("vehicle.advancedCombine.grainTypes.grainType(%d)", i)
  104.         if not hasXMLProperty(self.xmlFile, key) then
  105.             break
  106.         end
  107.         i = i + 1
  108.         spec.grainTypes[i] = {}
  109.         spec.grainTypes[i].threshingDrumSpeed = math.min(math.max(getXMLInt(self.xmlFile, key.."#threshingDrumSpeed"), spec.combineSettings.baseInfos.threshingDrum.min), spec.combineSettings.baseInfos.threshingDrum.max)
  110.         spec.grainTypes[i].concave = math.min(math.max(getXMLInt(self.xmlFile, key.."#concave"), spec.combineSettings.baseInfos.concave.min), spec.combineSettings.baseInfos.concave.max)
  111.         spec.grainTypes[i].wind = math.min(math.max(getXMLInt(self.xmlFile, key.."#wind"), spec.combineSettings.baseInfos.wind.min), spec.combineSettings.baseInfos.wind.max)
  112.         spec.grainTypes[i].sieve = math.min(math.max(getXMLInt(self.xmlFile, key.."#sieve"), spec.combineSettings.baseInfos.sieve.min), spec.combineSettings.baseInfos.sieve.max)
  113.         spec.grainTypes[i].fruitTypes = {}
  114.         local types = StringUtil.splitString(" ", StringUtil.trim(getXMLString(self.xmlFile, key.."#fruitTypes")))
  115.         for k,v in pairs(types) do
  116.             local desc = g_fruitTypeManager:getFruitTypeByName(v)
  117.             if desc ~= nil then
  118.                 spec.grainTypes[i].fruitTypes[desc.index] = desc.name
  119.             end
  120.         end
  121.     end
  122.    
  123.     --spec.augerOnLight = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.advancedCombine.augerOnLight#node"), self.i3dMappings)
  124.     --spec.isUnloading = false
  125.    
  126.     local rotationPartNodeSpillnadel = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.advancedCombine.rotationPartSpillnadel#node"), self.i3dMappings)
  127.     if rotationPartNodeSpillnadel ~= nil then
  128.         spec.rotationPartSpillnadel = {}
  129.         spec.rotationPartSpillnadel.node = rotationPartNodeSpillnadel
  130.  
  131.         local x, y, z = StringUtil.getVectorFromString(getXMLString(self.xmlFile, "vehicle.advancedCombine.rotationPartSpillnadel#minRot"))
  132.         spec.rotationPartSpillnadel.minRot = {}
  133.         spec.rotationPartSpillnadel.minRot[1] = MathUtil.degToRad(Utils.getNoNil(x, 0))
  134.         spec.rotationPartSpillnadel.minRot[2] = MathUtil.degToRad(Utils.getNoNil(y, 0))
  135.         spec.rotationPartSpillnadel.minRot[3] = MathUtil.degToRad(Utils.getNoNil(z, 0))
  136.  
  137.         x, y, z = StringUtil.getVectorFromString(getXMLString(self.xmlFile, "vehicle.advancedCombine.rotationPartSpillnadel#maxRot"))
  138.         spec.rotationPartSpillnadel.maxRot = {}
  139.         spec.rotationPartSpillnadel.maxRot[1] = MathUtil.degToRad(Utils.getNoNil(x, 0))
  140.         spec.rotationPartSpillnadel.maxRot[2] = MathUtil.degToRad(Utils.getNoNil(y, 0))
  141.         spec.rotationPartSpillnadel.maxRot[3] = MathUtil.degToRad(Utils.getNoNil(z, 90))
  142.     end
  143.    
  144.     spec.spillValue = 0
  145.     spec.lastSpill = 0
  146.     spec.rawSpillValue = 0
  147.    
  148.     if self.loadDashboardsFromXML ~= nil then
  149.         self:loadDashboardsFromXML(self.xmlFile, "vehicle.advancedCombine.dashboards", {valueTypeToLoad = "speedRotorRPM", valueObject = spec, valueFunc = "speedDisplayLastValue", minFunc = 0, maxFunc = 2500})
  150.     end
  151.     spec.actualRotorSpeedValue = 0
  152.     spec.actualWindSpeedValue = 0
  153.     spec.rotorSpeedAdjustment = 0
  154.     spec.displayModeSpeed = true
  155.    
  156.     local curConcaveSetting = spec.combineSettings.baseInfos.concave.min
  157.     local curWindSetting = spec.combineSettings.baseInfos.wind.min
  158.     local curSieveSetting = spec.combineSettings.baseInfos.sieve.min
  159.     local curThreshingDrumSpeed = spec.combineSettings.baseInfos.threshingDrum.min
  160.     if savegame ~= nil then
  161.         --[[spec.rotorSpeedValue = Utils.getNoNil(getXMLFloat(savegame.xmlFile, string.format("%s.%s.advancedCombine#rotorSpeed", savegame.key, modName)), spec.rotorSpeedValue)
  162.         curConcaveSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.%s.advancedCombine#concave", savegame.key, modName)), curConcaveSetting)
  163.         curWindSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.%s.advancedCombine#wind", savegame.key, modName)), curWindSetting)
  164.         curSieveSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.%s.advancedCombine#sieve", savegame.key, modName)), curSieveSetting)]]
  165.         curThreshingDrumSpeed = Utils.getNoNil(getXMLFloat(savegame.xmlFile, string.format("%s.advancedCombine#threshingDrum", savegame.key)), curThreshingDrumSpeed)
  166.         curConcaveSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.advancedCombine#concave", savegame.key)), curConcaveSetting)
  167.         curWindSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.advancedCombine#wind", savegame.key)), curWindSetting)
  168.         curSieveSetting = Utils.getNoNil(getXMLInt(savegame.xmlFile, string.format("%s.advancedCombine#sieve", savegame.key)), curSieveSetting)
  169.     end
  170.     spec.combineSettings.currentSetting = {concave=curConcaveSetting, wind=curWindSetting, sieve=curSieveSetting, threshingDrum=curThreshingDrumSpeed}
  171.    
  172.     --if spec.grainTypeSwitch ~= nil then
  173.     --  setRotation(spec.grainTypeSwitch, spec.grainTypeSwitchRotation[1], spec.grainTypes[spec.threasherGrainTypeSelection].switchRotation, spec.grainTypeSwitchRotation[3])
  174.     --end
  175.     --setVisibility(spec.augerOnLight, false)
  176.     spec.speedDisplayDot = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.advancedCombine.speedDisplayDot#node"), self.i3dMappings)
  177.     if spec.speedDisplayDot ~= nil then
  178.         setVisibility(spec.speedDisplayDot, spec.displayModeSpeed)
  179.     end
  180.    
  181.     spec.speedDisplayTimeout = 0
  182.     spec.speedDisplayLastValue = 0
  183.    
  184.     spec.engineRpm2 = 0.3
  185.     -- NICHT ÄNDERN/ENTFERNEN!
  186.    
  187.     spec.engineRpm = 212.5
  188.     spec.engineSpeedAdjustment = 0
  189.    
  190.     spec.showHud = false
  191.    
  192.     spec.thresherSoundSample = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.advancedCombine", "thresherSound", self.baseDirectory, self.components[1].node, 1, AudioGroup.VEHICLE, nil, self)
  193.     spec.chopperSoundSample = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.advancedCombine", "chopperSound", self.baseDirectory, self.components[1].node, 1, AudioGroup.VEHICLE, nil, self)
  194.     spec.chopperSoundVolumeCoeff = 0
  195.    
  196.     spec.hud = {}
  197.     local uiScale = g_gameSettings.uiScale
  198.     local w, h = getNormalizedScreenValues(400 * uiScale, 200 * uiScale)
  199.     local w2, h2 = getNormalizedScreenValues(25 * uiScale, 25 * uiScale)
  200.     local baseX = 1-(g_safeFrameOffsetX/2)-w
  201.     local baseY = 0.6
  202.     spec.hud.main = Overlay:new(modDirectory .. "achud.dds", baseX, baseY, w, h)
  203.     local imagePath = modDirectory .. "acicons.dds"
  204.     spec.hud.icon1 = Overlay:new(imagePath, baseX, baseY-0.04, w2, h2) --drum
  205.     spec.hud.icon1:setUVs(getNormalizedUVs({0,0,64,64}, {256,64}))
  206.     spec.hud.icon2 = Overlay:new(imagePath, baseX+w2, baseY-0.04, w2, h2) --concave
  207.     spec.hud.icon2:setUVs(getNormalizedUVs({64,0,64,64}, {256,64}))
  208.     spec.hud.icon3 = Overlay:new(imagePath, baseX+w2*2, baseY-0.04, w2, h2) --wind
  209.     spec.hud.icon3:setUVs(getNormalizedUVs({128,0,64,64}, {256,64}))
  210.     spec.hud.icon4 = Overlay:new(imagePath, baseX+w2*3, baseY-0.04, w2, h2) --sieve
  211.     spec.hud.icon4:setUVs(getNormalizedUVs({192,0,64,64}, {256,64}))
  212.    
  213.     spec.hud.bg = Overlay:new(modDirectory .. "achud.dds", baseX, baseY, w, h)
  214.     spec.hud.bg:setUVs(getNormalizedUVs({420,80,128,128}, {1024,512}))
  215.     spec.hud.bg:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_RIGHT)
  216.     spec.hud.bg:setColor(0.015, 0.015, 0.015, 0.7)
  217. end
  218.  
  219. function advancedCombine:onDelete()
  220.     g_soundManager:deleteSample(self.spec_advancedCombine.thresherSoundSample)
  221.     g_soundManager:deleteSample(self.spec_advancedCombine.chopperSoundSample)
  222. end
  223.  
  224. function advancedCombine:saveToXMLFile(xmlFile, key, usedModNames)
  225.     local spec = self.spec_advancedCombine
  226.     setXMLInt(xmlFile, string.sub(key, 1, string.find(key, "vehicle%(%d%)")+10).."advancedCombine#threshingDrum", spec.combineSettings.currentSetting.threshingDrum)
  227.     setXMLInt(xmlFile, string.sub(key, 1, string.find(key, "vehicle%(%d%)")+10).."advancedCombine#concave", spec.combineSettings.currentSetting.concave)
  228.     setXMLInt(xmlFile, string.sub(key, 1, string.find(key, "vehicle%(%d%)")+10).."advancedCombine#wind", spec.combineSettings.currentSetting.wind)
  229.     setXMLInt(xmlFile, string.sub(key, 1, string.find(key, "vehicle%(%d%)")+10).."advancedCombine#sieve", spec.combineSettings.currentSetting.sieve)
  230. end
  231.  
  232. function advancedCombine:onUpdate(dt)
  233.     local spec = self.spec_advancedCombine
  234.    
  235.     if self:getIsEntered() then
  236.         if spec.displayModeSpeed then
  237.             spec.speedDisplayLastValue = self:getLastSpeed() * 100
  238.         else
  239.             spec.speedDisplayLastValue = spec.actualRotorSpeedValue
  240.         end
  241.     end
  242.    
  243.     if spec.rotorSpeedAdjustment == 1 then
  244.         if spec.combineSettings.currentSetting.threshingDrum < spec.combineSettings.baseInfos.threshingDrum.max then
  245.             spec.combineSettings.currentSetting.threshingDrum = math.min(spec.combineSettings.currentSetting.threshingDrum + 0.03 * dt * spec.combineSettings.baseInfos.threshingDrum.changeSpeed, spec.combineSettings.baseInfos.threshingDrum.max)
  246.         end
  247.         spec.rotorSpeedAdjustment = 0
  248.     elseif spec.rotorSpeedAdjustment == -1 then
  249.         if spec.combineSettings.currentSetting.threshingDrum > spec.combineSettings.baseInfos.threshingDrum.min then
  250.             spec.combineSettings.currentSetting.threshingDrum = math.max(spec.combineSettings.currentSetting.threshingDrum - 0.03 * dt * spec.combineSettings.baseInfos.threshingDrum.changeSpeed, spec.combineSettings.baseInfos.threshingDrum.min)
  251.         end
  252.         spec.rotorSpeedAdjustment = 0
  253.     end
  254.    
  255.     if spec.engineSpeedAdjustment == 1 then
  256.         if spec.engineRpm < 550 then
  257.             spec.engineRpm = math.min(spec.engineRpm + 0.15 * dt, 550)
  258.         end
  259.     elseif spec.engineSpeedAdjustment == -1 then
  260.         if spec.engineRpm > 212.5 then
  261.             spec.engineRpm = math.max(spec.engineRpm - 0.15 * dt, 212.5)
  262.         end
  263.     end
  264.  
  265.     if self:getIsTurnedOn() then
  266.         if spec.actualRotorSpeedValue < spec.combineSettings.currentSetting.threshingDrum then
  267.             spec.actualRotorSpeedValue = math.min(spec.actualRotorSpeedValue + 0.5*dt, spec.combineSettings.currentSetting.threshingDrum)
  268.         elseif spec.actualRotorSpeedValue > spec.combineSettings.currentSetting.threshingDrum then
  269.             spec.actualRotorSpeedValue = math.max(spec.actualRotorSpeedValue - 0.5*dt, spec.combineSettings.currentSetting.threshingDrum)
  270.         end
  271.         local windTarget = math.floor((spec.actualRotorSpeedValue/spec.combineSettings.currentSetting.threshingDrum)*spec.combineSettings.currentSetting.wind)
  272.         if spec.actualWindSpeedValue < windTarget then
  273.             spec.actualWindSpeedValue = math.min(spec.actualWindSpeedValue + 0.4*dt, windTarget)
  274.         elseif spec.actualWindSpeedValue > windTarget then
  275.             spec.actualWindSpeedValue = math.max(spec.actualWindSpeedValue - 0.4*dt, windTarget)
  276.         end
  277.     else
  278.         if spec.actualRotorSpeedValue > 0 then
  279.             spec.actualRotorSpeedValue = math.max(spec.actualRotorSpeedValue - 0.15 * dt, 0)
  280.         end
  281.         if spec.actualWindSpeedValue > 0 then
  282.             local windTarget = math.floor((spec.actualRotorSpeedValue/spec.combineSettings.currentSetting.threshingDrum)*spec.combineSettings.currentSetting.wind)
  283.             spec.actualWindSpeedValue = math.max(spec.actualWindSpeedValue - 0.15 * dt, 0, windTarget)
  284.         end
  285.     end
  286.     if spec.actualRotorSpeedValue > 200 then
  287.         if not g_soundManager:getIsSamplePlaying(spec.thresherSoundSample) then
  288.             g_soundManager:playSample(spec.thresherSoundSample, 0)
  289.         end
  290.     else
  291.         if g_soundManager:getIsSamplePlaying(spec.thresherSoundSample) then
  292.             g_soundManager:stopSample(spec.thresherSoundSample)
  293.         end
  294.     end
  295.    
  296.     if self.spec_combine.chopperPSenabled then
  297.         if not g_soundManager:getIsSamplePlaying(spec.chopperSoundSample) then
  298.             g_soundManager:playSample(spec.chopperSoundSample, 0)
  299.         end
  300.         if spec.chopperSoundVolumeCoeff < 1 then
  301.             spec.chopperSoundVolumeCoeff = math.min(spec.chopperSoundVolumeCoeff + dt/900, 1)
  302.         end
  303.     else
  304.         if spec.chopperSoundVolumeCoeff > 0 then
  305.             spec.chopperSoundVolumeCoeff = math.max(spec.chopperSoundVolumeCoeff - dt/400, 0)
  306.         end
  307.         if spec.chopperSoundVolumeCoeff == 0 and g_soundManager:getIsSamplePlaying(spec.chopperSoundSample) then
  308.             g_soundManager:stopSample(spec.chopperSoundSample)
  309.         end
  310.     end
  311.    
  312.     self:calculateSpill(dt)
  313.    
  314.     self.spec_combine.threshingScale = (100 - math.max(spec.rawSpillValue, 0)) * 0.01
  315.    
  316.     --[[if self.isClient then
  317.         local isUnloading = self:getDischargeState() ~= Dischargeable.DISCHARGE_STATE_OFF
  318.         if g_manualDischargeUtil ~= nil then
  319.             local specManualDischarge = g_manualDischargeUtil.getSpecByName(self, "manualDischarge")
  320.             isUnloading = specManualDischarge.allowDischarge and self:getDischargeState() ~= Dischargeable.DISCHARGE_STATE_OFF
  321.         end
  322.         if isUnloading and not spec.isUnloading then
  323.             setVisibility(self.spec_advancedCombine.augerOnLight, true)
  324.             spec.isUnloading = true
  325.         elseif not isUnloading and spec.isUnloading then
  326.             setVisibility(self.spec_advancedCombine.augerOnLight, false)
  327.             spec.isUnloading = false
  328.         end
  329.     end]]
  330. end
  331.  
  332. function advancedCombine:onDraw()
  333.     if self:getIsEntered() then
  334.         local spec = self.spec_advancedCombine
  335.         if spec.showHud then
  336.             setTextAlignment(RenderText.ALIGN_RIGHT)
  337.             local uiScale = g_gameSettings.uiScale
  338.            
  339.             local fontSize = 0.015 * uiScale
  340.             local baseX = 1 - g_safeFrameOffsetX - fontSize
  341.             local baseY = g_safeFrameOffsetY + g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterY * 3
  342.             local textoffset = fontSize*1.3
  343.            
  344.             setTextBold(false)
  345.             local s1, n1, n2, n3, n4 = advancedCombine.getMaxTextLength(self)
  346.             local col4 = baseX-n4-0.002
  347.             local col3 = col4-n3-0.007
  348.             local col2 = col3-n2-0.007
  349.             local col1 = col2-n1-s1*1.2-0.007
  350.            
  351.             for i,grainType in ipairs(spec.grainTypes) do
  352.                 for k,fruitType in pairs(grainType.fruitTypes) do
  353.                     local filltypeindex = g_fruitTypeManager:getFillTypeIndexByFruitTypeIndex(k)
  354.                     local filltypename = g_fillTypeManager:getFillTypeByIndex(filltypeindex).title
  355.                     if self:getFillUnitFillType(1) == filltypeindex then
  356.                         setTextColor(0.25, 1, 0.25, 1)
  357.                     else
  358.                         setTextColor(1, 1, 1, 1)
  359.                     end
  360.                     setTextAlignment(RenderText.ALIGN_RIGHT)
  361.                     renderText(baseX, baseY+textoffset, fontSize, string.format("%d", grainType.sieve))
  362.                     renderText(col4, baseY+textoffset, fontSize, string.format("%d |", grainType.wind))
  363.                     renderText(col3, baseY+textoffset, fontSize, string.format("%d |", grainType.concave))
  364.                     renderText(col2, baseY+textoffset, fontSize, string.format("%d |", grainType.threshingDrumSpeed))
  365.                     setTextAlignment(RenderText.ALIGN_LEFT)
  366.                     renderText(col1, baseY+textoffset, fontSize, string.format("%s", filltypename..":"))
  367.                     textoffset = textoffset+fontSize*1.1
  368.                 end
  369.             end
  370.             setTextAlignment(RenderText.ALIGN_RIGHT)
  371.             setTextBold(true)
  372.             local w = spec.hud.icon1.width
  373.             spec.hud.bg:setPosition(baseX+fontSize,baseY)
  374.             spec.hud.bg:setDimension(baseX-col1+fontSize*2, textoffset+fontSize*4)
  375.             spec.hud.bg:render()
  376.             spec.hud.main:setPosition(spec.hud.main.x, baseY+textoffset+fontSize*5)
  377.             spec.hud.main:render()
  378.             spec.hud.icon1:setPosition(col2-w-n1/2, baseY+textoffset) --drum
  379.             spec.hud.icon1:render()
  380.             spec.hud.icon2:setPosition(col3-w-n2/2, baseY+textoffset) --concave
  381.             spec.hud.icon2:render()
  382.             spec.hud.icon3:setPosition(col4-w-n3/2, baseY+textoffset) --wind
  383.             spec.hud.icon3:render()
  384.             spec.hud.icon4:setPosition(baseX-w, baseY+textoffset) --sieve
  385.             spec.hud.icon4:render()
  386.             local w, h = spec.hud.main.width, spec.hud.main.height
  387.             local spillcolor = 1 - math.min(spec.rawSpillValue/10, 1)
  388.             setTextColor(1, spillcolor, spillcolor, 1)
  389.             renderText(spec.hud.main.x+w*0.92, spec.hud.main.y+h*0.085, h/10, string.format("%d %%", spec.rawSpillValue)) -- spill display in HUD
  390.             setTextColor(1, 1, 1, 1)
  391.             renderText(spec.hud.main.x+w*0.76, spec.hud.main.y+h*0.395, h/10, string.format("%d", spec.combineSettings.currentSetting.sieve)) -- sieve display in HUD
  392.             renderText(spec.hud.main.x+w*0.51, spec.hud.main.y+h*0.24, h/10, string.format("%d", spec.actualWindSpeedValue)) -- wind display in HUD
  393.             renderText(spec.hud.main.x+w*0.307, spec.hud.main.y+h*0.285, h/10, string.format("%d", spec.combineSettings.currentSetting.concave)) -- concave display in HUD
  394.             renderText(spec.hud.main.x+w*0.373, spec.hud.main.y+h*0.41, h/10, string.format("%d", spec.actualRotorSpeedValue)) -- concave display in HUD
  395.             textoffset = textoffset+fontSize*2
  396.             setTextAlignment(RenderText.ALIGN_LEFT)
  397.             renderText(col1, baseY+textoffset, fontSize*1.2, g_i18n:getText("HUD_HARVESTER_SETTINGS"))
  398.             setTextBold(false)
  399.         end
  400.     end
  401. end
  402.  
  403.  
  404. function advancedCombine:getRotorRpm()
  405.     return self.spec_advancedCombine.actualRotorSpeedValue/self.spec_advancedCombine.combineSettings.baseInfos.threshingDrum.max
  406. end
  407. function advancedCombine:getMinRotorRpm()
  408.     return 0
  409. end
  410. function advancedCombine:getMaxRotorRpm()
  411.     return 1
  412. end
  413.  
  414. function advancedCombine:getCameraRot()
  415.     if self:getIsEntered() and not self.spec_enterable.activeCamera.isInside then
  416.         local rotation = math.deg(self.spec_enterable.activeCamera.rotY % (2*math.pi))
  417.         return rotation/360
  418.     end
  419.     return 0
  420. end
  421. function advancedCombine:getMinCamRot()
  422.     return 0
  423. end
  424. function advancedCombine:getMaxCamRot()
  425.     return 1
  426. end
  427.  
  428. function advancedCombine:getChopperVolume()
  429.     return self.spec_advancedCombine.chopperSoundVolumeCoeff
  430. end
  431. function advancedCombine:getMinChopperVolume()
  432.     return 0
  433. end
  434. function advancedCombine:getMaxChopperVolume()
  435.     return 1
  436. end
  437.  
  438. function advancedCombine:getCorrectGrainTypeSelection(fruitType)
  439.     for i,grainType in pairs(self.spec_advancedCombine.grainTypes) do
  440.         for k,v in pairs(grainType.fruitTypes) do
  441.             if fruitType == k then
  442.                 return i
  443.             end
  444.         end
  445.     end
  446. end
  447.  
  448. function advancedCombine:getMaxTextLength()
  449.     local maxLengthFruit = 0
  450.     local maxLengthDrum = 0
  451.     local maxLengthConcave = 0
  452.     local maxLengthWind = 0
  453.     local maxLengthSieve = 0
  454.     local uiScale = g_gameSettings.uiScale
  455.     for i,grainType in pairs(self.spec_advancedCombine.grainTypes) do
  456.         for k,fruitType in pairs(grainType.fruitTypes) do
  457.             local filltypeindex = g_fruitTypeManager:getFillTypeIndexByFruitTypeIndex(k)
  458.             local filltypename = g_fillTypeManager:getFillTypeByIndex(filltypeindex).title
  459.             maxLengthFruit = math.max(maxLengthFruit, getTextWidth(0.015 * uiScale, filltypename))
  460.             maxLengthDrum = math.max(maxLengthDrum, getTextWidth(0.015 * uiScale, tostring(grainType.threshingDrumSpeed)))
  461.             maxLengthConcave = math.max(maxLengthConcave, getTextWidth(0.015 * uiScale, tostring(grainType.concave)))
  462.             maxLengthWind = math.max(maxLengthWind, getTextWidth(0.015 * uiScale, tostring(grainType.wind)))
  463.             maxLengthSieve = math.max(maxLengthSieve, getTextWidth(0.015 * uiScale, tostring(grainType.sieve)))
  464.         end
  465.     end
  466.     return maxLengthFruit, maxLengthDrum, maxLengthConcave, maxLengthWind, maxLengthSieve
  467. end
  468.  
  469. function advancedCombine:calculateSpill(dt)
  470.     local spec = self.spec_advancedCombine
  471.     local spill = 0
  472.    
  473.     if self.spec_combine.lastAreaZeroTime < 250 then --self.spec_combine.lastArea > 0 then
  474.         local currentGrainTankFruitType = g_fruitTypeManager:getFruitTypeByFillTypeIndex(self:getFillUnitFillType(self.spec_combine.fillUnitIndex))
  475.         if currentGrainTankFruitType ~= nil then
  476.             local spillDrum = 0
  477.             local spillConcave = 0
  478.             local spillWind = 0
  479.             local spillSieve = 0
  480.            
  481.             for i,grainType in pairs(spec.grainTypes) do
  482.                 for k,fruitType in pairs(grainType.fruitTypes) do
  483.                     if currentGrainTankFruitType.index == k then
  484.                         local correctGT = self:getCorrectGrainTypeSelection(currentGrainTankFruitType.index)
  485.                         local drum = spec.grainTypes[correctGT].threshingDrumSpeed
  486.                         local concave = spec.grainTypes[correctGT].concave
  487.                         local wind = spec.grainTypes[correctGT].wind
  488.                         local sieve = spec.grainTypes[correctGT].sieve
  489.                        
  490.                         spillDrum = math.abs(math.floor(spec.actualRotorSpeedValue) - drum) * 0.12
  491.                         spillConcave = (spec.combineSettings.currentSetting.concave - concave) * 2
  492.                         if spillConcave < 0 then
  493.                             spillConcave = spillConcave * -0.75
  494.                         end
  495.                         spillWind = (spec.combineSettings.currentSetting.wind - wind) * 0.1
  496.                         if spillWind < 0 then
  497.                             spillWind = spillWind * -0.6
  498.                         end
  499.                         spillSieve = (spec.combineSettings.currentSetting.sieve - sieve)
  500.                         if spillSieve < 0 then
  501.                             spillSieve = spillSieve * -1.5
  502.                         end
  503.                         break
  504.                     end
  505.                 end
  506.             end
  507.             spill = spillDrum + spillConcave + spillWind + spillSieve
  508.         end
  509.     else
  510.         spill = 0
  511.     end
  512.    
  513.     if spill > 99 then
  514.         spill = 99
  515.     end
  516.    
  517.     spec.rawSpillValue = spill
  518.    
  519.     local adjustedSpill = 0
  520.     if self.spec_combine.lastAreaZeroTime < 1000 then
  521.         adjustedSpill = spill/1.05 + 5
  522.     end
  523.    
  524.     if spec.lastSpill < adjustedSpill then
  525.         spec.spillValue = math.min(spec.lastSpill + 0.1 * dt, adjustedSpill)
  526.     elseif spec.lastSpill > adjustedSpill then
  527.         spec.spillValue = math.max(spec.lastSpill - 0.1 * dt, adjustedSpill)
  528.     elseif adjustedSpill == 0 then
  529.         spec.spillValue = 0
  530.     end
  531.    
  532.     spec.lastSpill = spec.spillValue
  533.     if spec.rotationPartSpillnadel ~= nil then
  534.         local x, y, z = getRotation(spec.rotationPartSpillnadel.node)
  535.         z = ((spec.rotationPartSpillnadel.maxRot[3] - spec.rotationPartSpillnadel.minRot[3]) / 100) * spec.spillValue + spec.rotationPartSpillnadel.minRot[3]
  536.         setRotation(spec.rotationPartSpillnadel.node, x, y ,z)
  537.     end
  538. end
  539.  
  540. function advancedCombine.processActionEvent(self, actionName, inputValue, callbackState, isAnalog)
  541.     local spec = self.spec_advancedCombine
  542.    
  543.     if actionName == "TOGGLE_DISPLAY_MODE" then
  544.         spec.displayModeSpeed = not spec.displayModeSpeed
  545.         if spec.speedDisplayDot ~= nil then
  546.             setVisibility(spec.speedDisplayDot, spec.displayModeSpeed)
  547.         end
  548.     end
  549.     if actionName == "SHOW_SPILL_HUD" then
  550.         spec.showHud = not spec.showHud
  551.         for k,eventId in pairs(spec.actionEventIds) do
  552.             g_inputBinding:setActionEventTextVisibility(eventId, spec.showHud)
  553.         end
  554.     end
  555. end
  556.  
  557. function advancedCombine.actionEventThresherRPM(self, actionName, inputValue, callbackState, isAnalog)
  558.     self.spec_advancedCombine.rotorSpeedAdjustment = MathUtil.sign(inputValue)
  559. end
  560.  
  561. function advancedCombine.actionEventConcave(self, actionName, inputValue, callbackState, isAnalog)
  562.     local spec = self.spec_advancedCombine
  563.     local dir = MathUtil.sign(inputValue)
  564.     spec.combineSettings.currentSetting.concave = math.min(math.max(spec.combineSettings.currentSetting.concave + (spec.combineSettings.baseInfos.concave.changeStep * dir), spec.combineSettings.baseInfos.concave.min), spec.combineSettings.baseInfos.concave.max)
  565. end
  566.  
  567. function advancedCombine.actionEventWindRPM(self, actionName, inputValue, callbackState, isAnalog)
  568.     local spec = self.spec_advancedCombine
  569.     local dir = MathUtil.sign(inputValue)
  570.     spec.combineSettings.currentSetting.wind = math.min(math.max(spec.combineSettings.currentSetting.wind + (spec.combineSettings.baseInfos.wind.changeStep * dir), spec.combineSettings.baseInfos.wind.min), spec.combineSettings.baseInfos.wind.max)
  571. end
  572.  
  573. function advancedCombine.actionEventSieve(self, actionName, inputValue, callbackState, isAnalog)
  574.     local spec = self.spec_advancedCombine
  575.     local dir = MathUtil.sign(inputValue)
  576.     spec.combineSettings.currentSetting.sieve = math.min(math.max(spec.combineSettings.currentSetting.sieve + (spec.combineSettings.baseInfos.sieve.changeStep * dir), spec.combineSettings.baseInfos.sieve.min), spec.combineSettings.baseInfos.sieve.max)
  577. end
Advertisement
Add Comment
Please, Sign In to add comment