aboutsummaryrefslogtreecommitdiff
path: root/advtrains/wagons.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-11-22 20:29:57 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-11-22 20:29:57 +0100
commitca4d65050ccb6ac7f7a54c491250c632a50b6d23 (patch)
treeb77103ac24bfadeec36ea65f7a784fc9ceeae58b /advtrains/wagons.lua
parent0252768c1619f9ae5cc1da2f5ad476f44ccff36c (diff)
downloadadvtrains-ca4d65050ccb6ac7f7a54c491250c632a50b6d23.tar.gz
advtrains-ca4d65050ccb6ac7f7a54c491250c632a50b6d23.tar.bz2
advtrains-ca4d65050ccb6ac7f7a54c491250c632a50b6d23.zip
Add wagon_width attribute
This allows for wider vehicles than trains, such as boats to discharge the passengers onto the platforms.
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r--advtrains/wagons.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index b67449d..8ff1d7e 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -45,6 +45,7 @@ local wagon={
textures = {"black.png"},
is_wagon=true,
wagon_span=1,--how many index units of space does this wagon consume
+ wagon_width=3, -- Wagon width in meters
has_inventory=false,
static_save=false,
}
@@ -694,12 +695,17 @@ function wagon:get_off(seatno)
local fct=data.wagon_flipped and -1 or 1
local aci = advtrains.path_get_index_by_offset(train, index, ino*fct)
local ix1, ix2 = advtrains.path_get_adjacent(train, aci)
+ local d = train.door_open
+ if self.wagon_width then
+ d = d * math.floor(self.wagon_width/2)
+ end
-- the two wanted positions are ix1 and ix2 + (2nd-1st rotated by 90deg)
-- (x z) rotated by 90deg is (-z x) (http://stackoverflow.com/a/4780141)
- local add = { x = (ix2.z-ix1.z)*train.door_open, y = 0, z = (ix1.x-ix2.x)*train.door_open }
- local oadd = { x = (ix2.z-ix1.z)*train.door_open*2, y = 1, z = (ix1.x-ix2.x)*train.door_open*2}
+ local add = { x = (ix2.z-ix1.z)*d, y = 0, z = (ix1.x-ix2.x)*d }
+ local oadd = { x = (ix2.z-ix1.z)*(d+train.door_open), y = 1, z = (ix1.x-ix2.x)*(d+train.door_open)}
local platpos=vector.round(vector.add(ix1, add))
local offpos=vector.round(vector.add(ix1, oadd))
+
--atdebug("platpos:", platpos, "offpos:", offpos)
if minetest.get_item_group(minetest.get_node(platpos).name, "platform")>0 then
minetest.after(GETOFF_TP_DELAY, function() clicker:setpos(offpos) end)