Advertisement
JachyHm

Fyzikalni model adhese pro TS2019

Oct 27th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.30 KB | None | 0 0
  1. --------------ADHESNI MODEL---------
  2. rychlostMS = Call("GetSpeed")
  3.  
  4. if SysCall("ScenarioManager:GetCurrentPrecipitationType") < 3 then --nesnezi
  5.     if SysCall("ScenarioManager:GetPrecipitationDensity") > 0.3 then --prsi hodne
  6.         if adhese_casdeste == -1 then
  7.             adhese_casdeste = 0
  8.         end
  9.         if adhese_casdeste <= 370 then
  10.             adhese_casdeste = adhese_casdeste + deltaTime
  11.         end
  12.         adhese_caspodesti = -1
  13.     elseif SysCall("ScenarioManager:GetPrecipitationDensity") ~= 0 then --prsi trochenc
  14.         if adhese_casdeste == -1 then
  15.             adhese_casdeste = 0
  16.         end
  17.         adhese_caspodesti = -1
  18.     else --neprsi vubec
  19.         adhese_casdeste = -1
  20.         if adhese_casdeste ~= -1 then
  21.             adhese_caspodesti = adhese_casdeste*10
  22.         end
  23.         if adhese_caspodesti > 0 then
  24.             adhese_caspodesti = adhese_caspodesti - deltaTime
  25.         else
  26.             adhese_caspodesti = -1
  27.         end
  28.     end
  29.     --defaultne adhese za sucha
  30.     wh01_adhese = ADHESE_SUCHO
  31.     wh02_adhese = ADHESE_SUCHO
  32.     wh03_adhese = ADHESE_SUCHO
  33.     wh04_adhese = ADHESE_SUCHO
  34.     if adhese_casdeste ~= -1 then --pokud prsi
  35.         if adhese_casdeste < ADHESE_VLHKO_CAS_NABEH then --a prsi mene jak ADHESE_VLHKO_CAS_NABEH (70 vterin) - adhese se znizuje az na ADHESE_VLHKO_START (0.5)
  36.             wh01_adhese = ADHESE_SUCHO - (ADHESE_SUCHO-ADHESE_VLHKO_START)*(adhese_casdeste/ADHESE_VLHKO_CAS_NABEH)
  37.             wh02_adhese = ADHESE_SUCHO - (ADHESE_SUCHO-ADHESE_VLHKO_START)*(adhese_casdeste/ADHESE_VLHKO_CAS_NABEH)
  38.             wh03_adhese = ADHESE_SUCHO - (ADHESE_SUCHO-ADHESE_VLHKO_START)*(adhese_casdeste/ADHESE_VLHKO_CAS_NABEH)
  39.             wh04_adhese = ADHESE_SUCHO - (ADHESE_SUCHO-ADHESE_VLHKO_START)*(adhese_casdeste/ADHESE_VLHKO_CAS_NABEH)
  40.         elseif adhese_casdeste < ADHESE_VLHKO_CAS_SNIZENI then --nebo prsi mene jak ADHESE_VLHKO_CAS_SNIZENI (370 vterin) - adhese se zvysuje na ADHESE_VLHKO (0.7)
  41.             wh01_adhese = ADHESE_VLHKO_START - (ADHESE_VLHKO_START-ADHESE_VLHKO)*(adhese_casdeste/(ADHESE_VLHKO_CAS_NABEH+ADHESE_VLHKO_CAS_SNIZENI))
  42.             wh02_adhese = ADHESE_VLHKO_START - (ADHESE_VLHKO_START-ADHESE_VLHKO)*(adhese_casdeste/(ADHESE_VLHKO_CAS_NABEH+ADHESE_VLHKO_CAS_SNIZENI))
  43.             wh03_adhese = ADHESE_VLHKO_START - (ADHESE_VLHKO_START-ADHESE_VLHKO)*(adhese_casdeste/(ADHESE_VLHKO_CAS_NABEH+ADHESE_VLHKO_CAS_SNIZENI))
  44.             wh04_adhese = ADHESE_VLHKO_START - (ADHESE_VLHKO_START-ADHESE_VLHKO)*(adhese_casdeste/(ADHESE_VLHKO_CAS_NABEH+ADHESE_VLHKO_CAS_SNIZENI))
  45.         else --jinak uz je adhese stala ADHESE_VLHKO (0.7)
  46.             wh01_adhese = ADHESE_VLHKO
  47.             wh02_adhese = ADHESE_VLHKO
  48.             wh03_adhese = ADHESE_VLHKO
  49.             wh04_adhese = ADHESE_VLHKO
  50.         end
  51.     elseif adhese_caspodesti ~= -1 then --pokud prselo pred mene jak 10 minutami, adhese se zvysuje od aktualni k ADHESE_SUCHO (0.9)
  52.         if wh01_vychozi_adhese_podesti == -1 then
  53.             wh01_vychozi_adhese_podesti = wh01_adhese
  54.         end
  55.         if wh02_vychozi_adhese_podesti == -1 then
  56.             wh02_vychozi_adhese_podesti = wh02_adhese
  57.         end
  58.         if wh03_vychozi_adhese_podesti == -1 then
  59.             wh03_vychozi_adhese_podesti = wh03_adhese
  60.         end
  61.         if wh04_vychozi_adhese_podesti == -1 then
  62.             wh04_vychozi_adhese_podesti = wh04_adhese
  63.         end
  64.         wh01_adhese = wh01_vychozi_adhese_podesti - (wh01_vychozi_adhese_podesti-ADHESE_SUCHO)*(adhese_caspodesti/ADHESE_VLHKO_PODESTI)
  65.         wh02_adhese = wh02_vychozi_adhese_podesti - (wh02_vychozi_adhese_podesti-ADHESE_SUCHO)*(adhese_caspodesti/ADHESE_VLHKO_PODESTI)
  66.         wh03_adhese = wh03_vychozi_adhese_podesti - (wh03_vychozi_adhese_podesti-ADHESE_SUCHO)*(adhese_caspodesti/ADHESE_VLHKO_PODESTI)
  67.         wh04_adhese = wh04_vychozi_adhese_podesti - (wh04_vychozi_adhese_podesti-ADHESE_SUCHO)*(adhese_caspodesti/ADHESE_VLHKO_PODESTI)
  68.     end
  69. else --snezi, tak nejsou casy deste
  70.     adhese_casdeste = -1
  71.     adhese_caspodesti = -1
  72. end
  73.  
  74. if adhese_caspodesti == -1 then --pokud uz neprsi vice jak 10 minut vynuluj vychozi pocitadla
  75.     wh01_vychozi_adhese_podesti = -1
  76.     wh02_vychozi_adhese_podesti = -1
  77.     wh03_vychozi_adhese_podesti = -1
  78.     wh04_vychozi_adhese_podesti = -1
  79. end
  80.  
  81. if SysCall("ScenarioManager:GetSeason") == 2 then --pokud je podzim, vsade jsou listy - klouze to 3x tolik
  82.     wh01_adhese = wh01_adhese * ADHESE_KOEF_LISTI
  83.     wh02_adhese = wh02_adhese * ADHESE_KOEF_LISTI
  84.     wh03_adhese = wh03_adhese * ADHESE_KOEF_LISTI
  85.     wh04_adhese = wh04_adhese * ADHESE_KOEF_LISTI
  86. elseif SysCall("ScenarioManager:GetSeason") == 2 then --pokud je zima, je snih - sankuje to 2x tolik jak obvykle
  87.     wh01_adhese = ADHESE_SNIH
  88.     wh02_adhese = ADHESE_SNIH
  89.     wh03_adhese = ADHESE_SNIH
  90.     wh04_adhese = ADHESE_SNIH
  91. end
  92.  
  93. if Call("GetControlValue","Sander",0) == 1 then --pokud ale piskuju, zvednu adhesi o 20%
  94.     wh01_adhese = wh01_adhese * ADHESE_KOEF_PISEK
  95.     wh02_adhese = wh02_adhese * ADHESE_KOEF_PISEK
  96.     wh03_adhese = wh03_adhese * ADHESE_KOEF_PISEK
  97.     wh04_adhese = wh04_adhese * ADHESE_KOEF_PISEK
  98. end
  99.  
  100. --spetka nahodnosti jeste nikoho nezabila, takze nechame adhesi trosenku hybat - o +/- 1%
  101. wh01_adhese = wh01_adhese * (math.random(9,11)/100)
  102. wh02_adhese = wh02_adhese * (math.random(9,11)/100)
  103. wh03_adhese = wh03_adhese * (math.random(9,11)/100)
  104. wh04_adhese = wh04_adhese * (math.random(9,11)/100)
  105.  
  106. --prvni naprava
  107. if wh01_PT > 0 then
  108.     if VratAdhesniKN(wh01_adhese, rychlostMS, 4) - VratTCh(wh01_PT, wh01_speed, 4) > 0 then
  109.         wh01_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh01_adhese, rychlostMS, 4) - VratTCh(wh01_PT, wh01_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh01_adhese, VratAdhesniKN(wh01_adhese, rychlostMS, 1)*0.3))
  110.         wh01_skutecnaFt = math.min(VratAdhesniKN(wh01_adhese, rychlostMS, 4), VratTCh(wh01_PT, wh01_speed, 4))
  111.     else
  112.         if VratTCh(wh01_PT, wh01_speed, 4) > VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3 then
  113.             wh01_speed = wh01_speed + (VratTCh(wh01_PT, wh01_speed, 4) - VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3) * deltaTime * 2
  114.         elseif VratTCh(wh01_PT, wh01_speed, 4) < VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3 then
  115.             wh01_speed = wh01_speed - ((VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3) - VratTCh(wh01_PT, wh01_speed, 4)) * deltaTime * 2
  116.         end
  117.         wh01_skutecnaFt = math.min(VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3, VratTCh(wh01_PT, wh01_speed, 4))
  118.     end
  119. elseif wh01_PT < 0 then
  120.     if VratAdhesniKN(wh01_adhese, rychlostMS, 4) - VratTCh(-wh01_PT, wh01_speed, 4) > 0 then
  121.         wh01_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh01_adhese, rychlostMS, 4) - VratTCh(-wh01_PT, wh01_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh01_adhese, VratAdhesniKN(wh01_adhese, rychlostMS, 1)*0.3))
  122.         wh01_skutecnaFt = math.max(-VratAdhesniKN(wh01_adhese, rychlostMS, 4), VratTCh(wh01_PT, wh01_speed, 4))
  123.     else
  124.         if VratTCh(-wh01_PT, wh01_speed, 4) > VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3 then
  125.             if wh01_speed > 0 then
  126.                 wh01_speed = wh01_speed - ((VratTCh(-wh01_PT, wh01_speed, 4) - VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3)) * deltaTime * 2
  127.             else
  128.                 wh01_speed = 0
  129.             end
  130.         elseif VratTCh(-wh01_PT, wh01_speed, 4) < VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3 then
  131.             wh01_speed = wh01_speed + ((VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3) - VratTCh(-wh01_PT, wh01_speed, 4)) * deltaTime * 2
  132.         end
  133.         wh01_skutecnaFt = math.max(-VratAdhesniKN(wh01_adhese, rychlostMS, 4)*0.3, VratTCh(wh01_PT, wh01_speed, 4))
  134.     end
  135. end
  136. --druha naprava
  137. if wh02_PT > 0 then
  138.     if VratAdhesniKN(wh02_adhese, rychlostMS, 4) - VratTCh(wh02_PT, wh02_speed, 4) > 0 then
  139.         wh02_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh02_adhese, rychlostMS, 4) - VratTCh(wh02_PT, wh02_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh02_adhese, VratAdhesniKN(wh02_adhese, rychlostMS, 1)*0.3))
  140.         wh02_skutecnaFt = math.min(VratAdhesniKN(wh02_adhese, rychlostMS, 4), VratTCh(wh02_PT, wh02_speed, 4))
  141.     else
  142.         if VratTCh(wh02_PT, wh02_speed, 4) > VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3 then
  143.             wh02_speed = wh02_speed + (VratTCh(wh02_PT, wh02_speed, 4) - VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3) * deltaTime * 2
  144.         elseif VratTCh(wh02_PT, wh02_speed, 4) < VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3 then
  145.             wh02_speed = wh02_speed - ((VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3) - VratTCh(wh02_PT, wh02_speed, 4)) * deltaTime * 2
  146.         end
  147.         wh02_skutecnaFt = math.min(VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3, VratTCh(wh02_PT, wh02_speed, 4))
  148.     end
  149. elseif wh02_PT < 0 then
  150.     if VratAdhesniKN(wh02_adhese, rychlostMS, 4) - VratTCh(-wh02_PT, wh02_speed, 4) > 0 then
  151.         wh02_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh02_adhese, rychlostMS, 4) - VratTCh(-wh02_PT, wh02_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh02_adhese, VratAdhesniKN(wh02_adhese, rychlostMS, 1)*0.3))
  152.         wh02_skutecnaFt = math.max(-VratAdhesniKN(wh02_adhese, rychlostMS, 4), VratTCh(wh02_PT, wh02_speed, 4))
  153.     else
  154.         if VratTCh(-wh02_PT, wh02_speed, 4) > VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3 then
  155.             if wh02_speed > 0 then
  156.                 wh02_speed = wh02_speed - ((VratTCh(-wh02_PT, wh02_speed, 4) - VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3)) * deltaTime * 2
  157.             else
  158.                 wh02_speed = 0
  159.             end
  160.         elseif VratTCh(-wh02_PT, wh02_speed, 4) < VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3 then
  161.             wh02_speed = wh02_speed + ((VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3) - VratTCh(-wh02_PT, wh02_speed, 4)) * deltaTime * 2
  162.         end
  163.         wh02_skutecnaFt = math.max(-VratAdhesniKN(wh02_adhese, rychlostMS, 4)*0.3, VratTCh(wh02_PT, wh02_speed, 4))
  164.     end
  165. end
  166. --treti naprava
  167. if wh03_PT > 0 then
  168.     if VratAdhesniKN(wh03_adhese, rychlostMS, 4) - VratTCh(wh03_PT, wh03_speed, 4) > 0 then
  169.         wh03_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh03_adhese, rychlostMS, 4) - VratTCh(wh03_PT, wh03_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh03_adhese, VratAdhesniKN(wh03_adhese, rychlostMS, 1)*0.3))
  170.         wh03_skutecnaFt = math.min(VratAdhesniKN(wh03_adhese, rychlostMS, 4), VratTCh(wh03_PT, wh03_speed, 4))
  171.     else
  172.         if VratTCh(wh03_PT, wh03_speed, 4) > VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3 then
  173.             wh03_speed = wh03_speed + (VratTCh(wh03_PT, wh03_speed, 4) - VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3) * deltaTime * 2
  174.         elseif VratTCh(wh03_PT, wh03_speed, 4) < VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3 then
  175.             wh03_speed = wh03_speed - ((VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3) - VratTCh(wh03_PT, wh03_speed, 4)) * deltaTime * 2
  176.         end
  177.         wh03_skutecnaFt = math.min(VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3, VratTCh(wh03_PT, wh03_speed, 4))
  178.     end
  179. elseif wh03_PT < 0 then
  180.     if VratAdhesniKN(wh03_adhese, rychlostMS, 4) - VratTCh(-wh03_PT, wh03_speed, 4) > 0 then
  181.         wh03_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh03_adhese, rychlostMS, 4) - VratTCh(-wh03_PT, wh03_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh03_adhese, VratAdhesniKN(wh03_adhese, rychlostMS, 1)*0.3))
  182.         wh03_skutecnaFt = math.max(-VratAdhesniKN(wh03_adhese, rychlostMS, 4), VratTCh(wh03_PT, wh03_speed, 4))
  183.     else
  184.         if VratTCh(-wh03_PT, wh03_speed, 4) > VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3 then
  185.             if wh03_speed > 0 then
  186.                 wh03_speed = wh03_speed - ((VratTCh(-wh03_PT, wh03_speed, 4) - VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3)) * deltaTime * 2
  187.             else
  188.                 wh03_speed = 0
  189.             end
  190.         elseif VratTCh(-wh03_PT, wh03_speed, 4) < VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3 then
  191.             wh03_speed = wh03_speed + ((VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3) - VratTCh(-wh03_PT, wh03_speed, 4)) * deltaTime * 2
  192.         end
  193.         wh03_skutecnaFt = math.max(-VratAdhesniKN(wh03_adhese, rychlostMS, 4)*0.3, VratTCh(wh03_PT, wh03_speed, 4))
  194.     end
  195. end
  196. --ctvrta naprava
  197. if wh04_PT > 0 then
  198.     if VratAdhesniKN(wh04_adhese, rychlostMS, 4) - VratTCh(wh04_PT, wh04_speed, 4) > 0 then
  199.         wh04_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh04_adhese, rychlostMS, 4) - VratTCh(wh04_PT, wh04_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh04_adhese, VratAdhesniKN(wh04_adhese, rychlostMS, 1)*0.3))
  200.         wh04_skutecnaFt = math.min(VratAdhesniKN(wh04_adhese, rychlostMS, 4), VratTCh(wh04_PT, wh04_speed, 4))
  201.     else
  202.         if VratTCh(wh04_PT, wh04_speed, 4) > VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3 then
  203.             wh04_speed = wh04_speed + (VratTCh(wh04_PT, wh04_speed, 4) - VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3) * deltaTime * 2
  204.         elseif VratTCh(wh04_PT, wh04_speed, 4) < VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3 then
  205.             wh04_speed = wh04_speed - ((VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3) - VratTCh(wh04_PT, wh04_speed, 4)) * deltaTime * 2
  206.         end
  207.         wh04_skutecnaFt = math.min(VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3, VratTCh(wh04_PT, wh04_speed, 4))
  208.     end
  209. elseif wh04_PT < 0 then
  210.     if VratAdhesniKN(wh04_adhese, rychlostMS, 4) - VratTCh(-wh04_PT, wh04_speed, 4) > 0 then
  211.         wh04_speed = math.min(rychlostMS*(1/(100*(VratAdhesniKN(wh04_adhese, rychlostMS, 4) - VratTCh(-wh04_PT, wh04_speed, 4))^3)+1), VratRychlostProAdhesniKN(wh04_adhese, VratAdhesniKN(wh04_adhese, rychlostMS, 1)*0.3))
  212.         wh04_skutecnaFt = math.max(-VratAdhesniKN(wh04_adhese, rychlostMS, 4), VratTCh(wh04_PT, wh04_speed, 4))
  213.     else
  214.         if VratTCh(-wh04_PT, wh04_speed, 4) > VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3 then
  215.             if wh04_speed > 0 then
  216.                 wh04_speed = wh04_speed - ((VratTCh(-wh04_PT, wh04_speed, 4) - VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3)) * deltaTime * 2
  217.             else
  218.                 wh04_speed = 0
  219.             end
  220.         elseif VratTCh(-wh04_PT, wh04_speed, 4) < VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3 then
  221.             wh04_speed = wh04_speed + ((VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3) - VratTCh(-wh04_PT, wh04_speed, 4)) * deltaTime * 2
  222.         end
  223.         wh04_skutecnaFt = math.max(-VratAdhesniKN(wh04_adhese, rychlostMS, 4)*0.3, VratTCh(wh04_PT, wh04_speed, 4))
  224.     end
  225. end
  226.  
  227. Call("SetControlValue", "ThrottleAndBrake", 0, wh01_skutecnaFt+wh02_skutecnaFt+wh03_skutecnaFt+wh04_skutecnaFt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement