Vehicles/SnowmakingManager.lua

SnowmakingManager implements the global snow cannon control system. All snow cannons are registered to SnowmakingManager and can be remote-controlled by script.

The table snowCannons contains all snow cannon instances and is also used for the slope map in the overview menu.

  29  SnowmakingManager                   = SnowmakingManager or {};
  30  SnowmakingManager.scanCompleted     = false;
  31  SnowmakingManager.closestSnowCannon = nil;
  32  SnowmakingManager.CONTROL_RANGE_SQR = 5*5;

SnowmakingManager:setup()

Is called upon initialisation of the game.

  36  function SnowmakingManager:setup()
  37      self.snowCannons                = {};
  38  end;

SnowmakingManager:registerVehicle(vehicle)

Is called once for each vehicle that has a SnowCannon VehicleScript attached to, when the vehicle is spawned. vehicle (table) is the vehicle instance.

  43  function SnowmakingManager:registerVehicle(vehicle)
  44      self.snowCannons[vehicle]       = true;
  45  end;

SnowmakingManager:unregisterVehicle(vehicle)

Is called once for each vehicle that is destroyed (i.e. sold, or destroyed upon closing the game). vehicle (table) again is the vehicle instance

  50  function SnowmakingManager:unregisterVehicle(vehicle)
  51      self.snowCannons[vehicle]       = nil;
  52  end;

SnowmakingManager:setGroupState(groupId, state)

Call this function to turn on/off all snow cannons in group groupId (int), depending on state (bool, true for on).

  56  function SnowmakingManager:setGroupState(groupId, state)
  57      for vehicle, _ in pairs(self.snowCannons) do
  58  
  59          -- check if this vehicle belongs to this group
  60          if vehicle.setIsCannonTurnedOn ~= nil and vehicle.snowCannonGroupId == groupId then
  61  
  62              -- yep, apply to this group
  63              vehicle:setIsCannonTurnedOn(nil, state);
  64          end;
  65      end;
  66  end;

SnowmakingManager:preUpdate(dt)

Internal use for performance optimization. Is called before any vehicle update.

  70  function SnowmakingManager:preUpdate(dt)
  71      SnowmakingManager.scanCompleted = false;
  72  end;

SnowmakingManager:getCannonActive(cannon)

Returns whether the given cannon (vehicle table) is currently active or not, i.e. whether the controls for this cannon should be displayed.

  76  function SnowmakingManager:getCannonActive(cannon)
  77      if not SnowmakingManager.scanCompleted then
  78          SnowmakingManager.scanCompleted     = true;
  79          SnowmakingManager.closestSnowCannon = self:getClosestSnowCannon();
  80      end;
  81  
  82      return SnowmakingManager.closestSnowCannon == cannon;
  83  end;

SnowmakingManager:getClosestSnowCannon()

Returns the vehicle table of the snow cannon that is closest to the player (if the distance between player and cannon is lower than SnowmakingManager.CONTROL_RANGE_SQR).

Please do not call this function from mods! Instead, please use SnowmakingManager:getCannonActive() due to performance reasons.

  89  function SnowmakingManager:getClosestSnowCannon()
  90      if g_scenario == nil or g_scenario.player == nil or not g_scenario.player:getIsLocalPlayerEntered() or not g_scenario.player:getIsInFirstPerson() or EscapeMenu.isActive then
  91          return nil;
  92      end;
  93  
  94      local player                    = g_scenario.player;
  95      local playerPos                 = Vector3:new(player.x, player.y, player.z);
  96      local minDist                   = -1;
  97      local activeCannon              = nil;
  98  
  99      for cannon, _ in pairs(self.snowCannons) do
 100          local cannonPos             = VectorUtils.getWorldPosition(cannon.controlId or cannon.mainId);
 101  
 102          local sqrDist               = (playerPos - cannonPos):sqrMagnitude();
 103          if sqrDist <= SnowmakingManager.CONTROL_RANGE_SQR and (activeCannon == nil or sqrDist < minDist) then
 104              activeCannon            = cannon;
 105              minDist                 = sqrDist;
 106          end;
 107      end;
 108      
 109      return activeCannon;
 110  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.