-- wagon.lua
-- Holds all logic related to wagons
-- From now on, wagons are, just like trains, just entries in a table
-- All data that is static is stored in the entity prototype (self).
-- A copy of the entity prototype is always available inside wagon_prototypes
-- All dynamic data is stored in the (new) wagons table
-- An entity is ONLY spawned by update_trainpart_properties when it finds it useful.
-- Only data that are only important to the entity itself are stored in the luaentity
advtrains.wagons = {}
advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {}
local setting_show_ids = minetest.settings:get_bool("advtrains_show_ids")
--
function advtrains.create_wagon(wtype, owner)
local new_id=advtrains.random_id()
while advtrains.wagons[new_id] do new_id=advtrains.random_id() end
local wgn = {}
wgn.type = wtype
wgn.seatp = {}
wgn.owner = owner
wgn.id = new_id
---wgn.train_id = train_id --- will get this via update_trainpart_properties
advtrains.wagons[new_id] = wgn
--atdebug("Created new wagon:",wgn)
return new_id
end
local wagon={
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
--physical = true,
visual = "mesh",
mesh = "wagon.b3d",
visual_size = {x=1, y=1},
textures = {"black.png"},
is_wagon=true,
wagon_span=1,--how many index units of space does this wagon consume
has_inventory=false,
static_save=false,
}
function wagon:train()
local data = advtrains.wagons[self.id]
return advtrains.trains[data.train_id]
end
function wagon:on_activate(sd_uid, dtime_s)
if sd_uid~="" then
--destroy when loaded from static block.
self.object:remove()
return
end
self.object:set_armor_groups({immortal=1})
end
local function invcallback(id, pname, rtallow, rtfail)
local data = advtrains.wagons[id]
if data and advtrains.check_driving_couple_protection(pname, data.owner, data.whitelist) then
return rtallow
end
return rtfail
end
function wagon:set_id(wid)
self.id = wid
self.initialized = true
local data = advtrains.wagons[self.id]
advtrains.wagon_objects[self.id] = self.object
--atdebug("Created wagon entity:",self.name," w_id",wid," t_id",data.train_id)
|