Vehicles/VehicleScripts/Seats.lua

Seats is the script which makes the vehicle enterable, i.e. without this script, you cannot enter the vehicle at all (neither via the Tab key nor by clicking some control element). The most common use-case of non-enterable vehicles are snow cannons. For most other vehicles (such as car, snowcats, snow mobiles, tractors, …) it makes sense to have this vehicle script active.

Generally, every time you can take place on a seat, this seat will be powered by VehicleSeat. This is true for vehicles and ropeway carriers, but also for stationary objects (e.g. sun deck chairs or the chairs in some ropeway control rooms).

Note: Seats supports multiple seats (that can be used either as second driver seat or as passenger seat). This means you can have multiple seats in your vehicle from which it can be controlled.

  29  Seats                               = Seats or {};

Seats:load(dataTable, isCarrier)

Load the configuration data (i.e. what seats are there and what cameras can be enabled). Currently, the camera slot can be between 1 and 4 (1 = interior camera, 2 = exterior camera, 3 and 4 = custom cameras)

Note that this function is also used to initialize the seats of ropeway carriers. In that case, self represents the ropeway carrier instance (instead of the vehicle instance). dataTable will be the carrier's data table.

  36  function Seats:load(dataTable, isCarrier)
  37      -- currently only supports doors
  38      self.seats                      = {};
  39      self.driverSeats                = {};
  40      self.driverSeat                 = nil; -- main driver seat (for tab function)
  41      self.nonTabbable                = self.nonTabbable or false; -- could be overridden by other vehicleScripts
  42      
  43      local cameras                   = {};
  44      for n, v in pairs(dataTable.cameras) do
  45          local camIndex              = v.index or "";
  46          local rotIndex              = v.rotIndex or "";
  47          local zoomIndex             = v.zoomIndex or "";
  48          local isInterieur           = v.isInterieur or false;
  49          
  50          local camId                 = getChild(self.id, camIndex);
  51          local rotId, zoomId         = nil, nil;
  52          
  53          if rotIndex ~= "" then      rotId   = getChild(self.id, rotIndex);      end;
  54          if zoomIndex ~= "" then     zoomId  = getChild(self.id, zoomIndex);     end;
  55          
  56          cameras[n]                  = VehicleCamera:new(camId, rotId, zoomId, isCarrier, self.mainId or self.id);
  57          cameras[n].slot             = v.slot or 2;
  58          cameras[n].isInterieur      = isInterieur;
  59      end;
  60      
  61      for i, v in pairs(dataTable.seats) do
  62          local seatIndex             = v.index or "";
  63          
  64          if seatIndex == "" then break else
  65              
  66              local colId             = getChild(self.id, seatIndex);
  67              local camId             = getChild(self.id, v.cameraIndex   or "");
  68              local leaveId           = getChild(self.id, v.leaveIndex    or "");
  69              
  70              local seat              = VehicleSeat:new(colId, camId, leaveId, isCarrier);
  71              seat.isDriverSeat       = v.isDriver or false;
  72              table.insert(self.seats, seat);
  73              
  74              if seat.isDriverSeat then
  75                  table.insert(self.driverSeats, seat);
  76                  
  77                  if self.driverSeat == nil then
  78                      self.driverSeat = seat;
  79                  end;
  80              end;
  81              
  82              for n, camera in pairs(cameras) do
  83                  local slotId        = camera.slot;
  84                  seat:addCamera(slotId, camera);
  85              end;
  86          end;
  87      end;
  88  
  89      self.isInterieurCamera          = true;
  90      
  91  end;

Seats:saveToTable(tbl, isCarrier)

Contrary to some other games, we always save the currently active camera position. If the player saves the game while sitting in a vehicle, that vehicle will also be active after loading the savegame, and even the same camera will be active.

  95  function Seats:saveToTable(tbl, isCarrier)
  96      if tbl == nil then return end;
  97  
  98      -- save all seats, but save cameras only once
  99      tbl.seats                       = {};
 100      local withoutCameras            = false;
 101  
 102      for k, v in pairs(self.seats) do
 103          -- note: for carriers, we only save the one seat where the player is actually sitting
 104          if not isCarrier or v.seatActive then
 105              tbl.seats[k]            = v:saveToTable(nil, withoutCameras);
 106              withoutCameras          = true;
 107          end;
 108      end;
 109  end;

Seats:loadFromTable(tbl)

Pass the data from our savegame on to the VehicleSeat.

 113  function Seats:loadFromTable(tbl)
 114      if tbl == nil then return end;
 115      if tbl.seats == nil then return end;
 116  
 117      for k, v in pairs(self.seats) do
 118          local seatTbl               = tbl.seats[k];
 119  
 120          if seatTbl ~= nil then
 121              v:loadFromTable(seatTbl);
 122          end;
 123      end;
 124  end;

Seats:update(dt)

Checks whether the vehicle is still active, and whether an interior camera is active (required for interior sound).

 128  function Seats:update(dt)
 129      -- check if we're entered somewhere
 130      local isEntered                 = false;
 131      for _, seat in pairs(self.driverSeats) do
 132          if seat.seatActive then
 133              isEntered               = true;
 134              self.isInterieurCamera  = seat.isInterieurCamera;
 135              break;
 136          end;
 137      end;
 138      self:setIsEntered(isEntered);
 139      
 140      -- don't update seats (this is done by BaseScenario)!
 141  end;

Seats:destroy()

 143  function Seats:destroy()
 144      for _, seat in pairs(self.seats) do
 145          seat:destroy();
 146      end;
 147  end;

Seats:enterByTab()

Activates the driver seat if the vehicle is entered using the Tab key.

 151  function Seats:enterByTab()
 152      -- enter into main driver seat
 153      self.driverSeat:enter();
 154      self:setIsEntered(true);
 155  end;

Seats:leaveByTab()

Deactivates all seats in this vehicle.

 159  function Seats:leaveByTab()
 160      -- leave all seats
 161      for n, seat in pairs(self.driverSeats) do
 162          if seat.seatActive then
 163              seat:leave();
 164          end;
 165      end;
 166      
 167      self:setIsEntered(false);
 168  end;

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

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