Vehicles/VehicleScripts/SnowBlade.lua

Handles the plowing of snow in front of the blade.

  25  SnowBlade                       = SnowBlade or {};

SnowBlade:load(dataTable)

Load the configuration data. Tweak the values in the dataTable, in this case, playing around with them is the best way to get going.

  29  function SnowBlade:load(dataTable)
  30      self.plowSnowByPosition     = VehicleManager:newFunction("plowSnowByPosition");
  31  
  32      if dataTable.snowBlade ~= nil then
  33          -- opening angle of the snow field
  34          self.bladeOpeningAngle                      = getNoNil(dataTable.snowBlade.bladeOpeningAngle, -20);
  35          -- distance between the middle pair of points, P3 and P4, gets multiplied with s and so we get the max value where snow in front the blade is effected
  36          self.bladeRangeCoefficient                  = getNoNil(dataTable.snowBlade.bladeRangeCoefficient, 1.5);
  37          -- simply a control parameter
  38          self.snowHillCoefficient                    = getNoNil(dataTable.snowBlade.snowHillCoefficient, 0.05);
  39          -- max height of snow in front of blade
  40          self.snowBlade_maxPlowHeight                = getNoNil(dataTable.snowBlade.maxPlowHeight, 220);
  41          -- snow can be removed completely or not (not implemented yet though)
  42          self.snowBlade_canRemoveSnowCompletely      = getNoNil(dataTable.snowBlade.canRemoveSnowCompletely, false);
  43  
  44          self.snowBladeP1                    = getChild(self.id, dataTable.snowBlade.leftBladeLeft);
  45          self.snowBladeP2                    = getChild(self.id, dataTable.snowBlade.leftBladeRight);
  46          self.snowBladeP3                    = getChild(self.id, dataTable.snowBlade.middleBladeLeft);
  47          self.snowBladeP4                    = getChild(self.id, dataTable.snowBlade.middleBladeRight);
  48          self.snowBladeP5                    = getChild(self.id, dataTable.snowBlade.rightBladeLeft);
  49          self.snowBladeP6                    = getChild(self.id, dataTable.snowBlade.rightBladeRight);
  50  
  51          -- how much snow the blade loses when going over ground without snow
  52          self.snowBlade_lossValue                    = 0;
  53      end;
  54  
  55      self.oldPositionSnowBlade = Vector3.up;
  56  end;
  57  

SnowBlade:fixedUpdate(dt)

Checks if snowcat has already travelled far enough and then issues the plowing of snow.

  61  function SnowBlade:fixedUpdate(dt)
  62      if g_isClient or not self.isActive or self.snowBladeP6 == nil then return end;
  63  
  64      local isGoingForward            = self.currentSpeed >= 0.5;
  65      local isGoingBackward           = self.currentSpeed <= -0.5;
  66  
  67      local driveDirection            = VectorUtils.transformDirection(self.id, Vector3.forward);
  68  
  69      local snowBladev1                       = VectorUtils.getWorldPosition(self.snowBladeP1);
  70  
  71      local travelledDistanceSinceLastSnowUpdate = Vector3.magnitude(self.oldPositionSnowBlade - snowBladev1);
  72      local enforceUpdate = false;
  73      --check if plow has already travelled far enough to make an update of snow hill
  74      if (travelledDistanceSinceLastSnowUpdate > 0.08) then
  75          self.oldPositionSnowBlade   = snowBladev1;
  76          enforceUpdate       = true;
  77      end;
  78  
  79      if not enforceUpdate then return end;
  80  
  81      local snowBladev2                       = VectorUtils.getWorldPosition(self.snowBladeP2);
  82      local snowBladev3                       = VectorUtils.getWorldPosition(self.snowBladeP3);
  83      local snowBladev4                       = VectorUtils.getWorldPosition(self.snowBladeP4);
  84      local snowBladev5                       = VectorUtils.getWorldPosition(self.snowBladeP5);
  85      local snowBladev6                       = VectorUtils.getWorldPosition(self.snowBladeP6);
  86      
  87      
  88      --local numberOfUpdates = 0;
  89  
  90      --if (travelledDistanceSinceLastSnowUpdate > 0.05) then
  91      --  self.oldPosition    = snowBladev1;
  92      --  enforceUpdate       = true;
  93      --  numberOfUpdates     = Mathf.Max(math.floor(travelledDistanceSinceLastSnowUpdate / 0.05), 5);
  94  --
  95      --end;
  96  --
  97      --if enforceUpdate then
  98      --  while (numberOfUpdates > 0) do
  99      --      self:plowSnowByPosition(snowBladev1, snowBladev2, snowBladev3, snowBladev4, snowBladev5, snowBladev6, driveDirection, isGoingForward, isGoingBackward);
 100      --      numberOfUpdates = numberOfUpdates - 1;
 101      --  end;
 102      --end;
 103  
 104      if enforceUpdate then
 105          self:plowSnowByPosition(self.snowBlade_lossValue, snowBladev1, snowBladev2, snowBladev3, snowBladev4, snowBladev5, snowBladev6, driveDirection, isGoingForward, isGoingBackward);
 106      end;
 107      
 108  end; 
 109  
 110  function SnowBlade:plowSnowByPosition(...)
 111      
 112      SnowSystem.setPlowParameter(self.bladeOpeningAngle, self.bladeRangeCoefficient, self.snowHillCoefficient, self.snowBlade_maxPlowHeight, self.snowBlade_canRemoveSnowCompletely);
 113      SnowSystem.plowSnowByPosition(...);
 114      
 115      -- send event if this is a server
 116      -- never send it if this is a client (because the event is server->client only)
 117      if g_isServer then
 118          EventPlowSnow:send(self, ...);
 119      end;
 120      if g_isMaster then
 121          self.snowBlade_lossValue    = SnowSystem.getLossValue();
 122      end;
 123  end;

All contents of this page may be used for modding use for Winter Resort Simulator - Season 2 only. Any use exceeding this regulation is not permitted.

Copyright (C) HR Innoways, 2021. All Rights Reserved.