Add modifiable wagon extents
This will be required for advcarts
This commit is contained in:
parent
5fc6cc7f5b
commit
d78d07589d
|
@ -71,6 +71,13 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
|
|||
wagon_span=2,
|
||||
^- How far this wagon extends from its base position. Is the half of the wagon length.
|
||||
^- Used to determine in which distance the other wagons have to be positioned. Will require tweaking.
|
||||
extent_h = 1,
|
||||
^- Determines the collision box extent in x/z direction. Defaults to 1 (=3x3)
|
||||
^- The actual bounding box size is (extent_h*2)+1, so 0 means 1x1, 1 means 3x3 and 2 means 5x5
|
||||
extent_v = 2,
|
||||
^- Determines the collision box extent in y direction. Defaults to 2 (=3).
|
||||
^- The actual bounding box size is extent_v+1, so 0 means 1, 1 means 2, 2 means 3 a.s.o.
|
||||
|
||||
drops = {"default:steelblock 3"}
|
||||
^- List of itemstrings what to drop when the wagon is destroyed
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ local couple_max_dist=3
|
|||
minetest.register_entity("advtrains:discouple", {
|
||||
visual="sprite",
|
||||
textures = {"advtrains_discouple.png"},
|
||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||
visual_size = {x=1, y=1},
|
||||
collisionbox = {-0.3,-0.3,-0.3, 0.3,0.3,0.3},
|
||||
visual_size = {x=0.7, y=0.7},
|
||||
initial_sprite_basepos = {x=0, y=0},
|
||||
|
||||
is_discouple=true,
|
||||
|
@ -101,8 +101,8 @@ train2_is_backpos
|
|||
minetest.register_entity("advtrains:couple", {
|
||||
visual="sprite",
|
||||
textures = {"advtrains_couple.png"},
|
||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||
visual_size = {x=1, y=1},
|
||||
collisionbox = {-0.3,-0.3,-0.3, 0.3,0.3,0.3},
|
||||
visual_size = {x=0.7, y=0.7},
|
||||
initial_sprite_basepos = {x=0, y=0},
|
||||
|
||||
is_couple=true,
|
||||
|
@ -114,6 +114,7 @@ minetest.register_entity("advtrains:couple", {
|
|||
self.object:remove()
|
||||
return
|
||||
end
|
||||
self.object:set_armor_groups({immmortal=1})
|
||||
end)
|
||||
end,
|
||||
get_staticdata=function(self) return "COUPLE" end,
|
||||
|
|
|
@ -101,7 +101,7 @@ sid=function(id) if id then return string.sub(id, -6) end end
|
|||
|
||||
if minetest.settings:get_bool("advtrains_enable_debugging") then
|
||||
atprint=function(t, ...)
|
||||
local context=advtrains.atprint_context_tid
|
||||
local context=advtrains.atprint_context_tid or ""
|
||||
if not context then return end
|
||||
local text=advtrains.print_concat_table({t, ...})
|
||||
advtrains.drb_record(context, text)
|
||||
|
@ -303,7 +303,7 @@ advtrains.mainloop_runcnt=0
|
|||
minetest.register_globalstep(function(dtime_mt)
|
||||
return advtrains.pcall(function()
|
||||
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
|
||||
atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
|
||||
--atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
|
||||
--call load once. see advtrains.load() comment
|
||||
if not init_load then
|
||||
advtrains.load()
|
||||
|
|
|
@ -498,7 +498,8 @@ function advtrains.train_step_b(id, train, dtime)
|
|||
|
||||
-- when paths get cleared, the old indices set above will be up-to-date and represent the state in which the last run of this code was made
|
||||
local ifo, ifn, ibo, ibn = train.detector_old_index, atround(train.index), train.detector_old_end_index, atround(train.end_index)
|
||||
|
||||
--atprint(ifo,">", ifn, "<==>", ibo,">", ibn)
|
||||
|
||||
local path=train.path
|
||||
|
||||
if train.enter_node_all then
|
||||
|
@ -557,6 +558,10 @@ function advtrains.train_step_b(id, train, dtime)
|
|||
local train_moves=(train.velocity~=0)
|
||||
|
||||
if train_moves then
|
||||
|
||||
--TO BE REMOVED:
|
||||
if not train.extent_h then advtrains.update_trainpart_properties(id, train) end
|
||||
|
||||
local collpos
|
||||
local coll_grace=1
|
||||
if train.movedir==1 then
|
||||
|
@ -566,8 +571,8 @@ function advtrains.train_step_b(id, train, dtime)
|
|||
end
|
||||
if collpos then
|
||||
local rcollpos=advtrains.round_vector_floor_y(collpos)
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
for x=-train.extent_h,train.extent_h do
|
||||
for z=-train.extent_h,train.extent_h do
|
||||
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
|
||||
--- 8a Check collision ---
|
||||
if advtrains.detector.occupied(testpos, id) then
|
||||
|
@ -648,6 +653,8 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate)
|
|||
train.drives_on=advtrains.merge_tables(advtrains.all_tracktypes)
|
||||
--FIX: deep-copy the table!!!
|
||||
train.max_speed=20
|
||||
train.extent_h = 0;
|
||||
|
||||
local rel_pos=0
|
||||
local count_l=0
|
||||
for i, w_id in ipairs(train.trainparts) do
|
||||
|
@ -696,6 +703,8 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate)
|
|||
end
|
||||
end
|
||||
train.max_speed=math.min(train.max_speed, wagon.max_speed)
|
||||
train.extent_h = math.max(train.extent_h, wagon.extent_h or 1);
|
||||
|
||||
if i==1 then
|
||||
train.couple_lock_front=wagon.lock_couples
|
||||
end
|
||||
|
|
|
@ -415,9 +415,11 @@ function wagon:on_step(dtime)
|
|||
--checking for environment collisions(a 3x3 cube around the center)
|
||||
if not gp.recently_collided_with_env then
|
||||
local collides=false
|
||||
for x=-1,1 do
|
||||
for y=0,2 do
|
||||
for z=-1,1 do
|
||||
local exh = self.extent_h or 1
|
||||
local exv = self.extent_v or 2
|
||||
for x=-exh,exh do
|
||||
for y=0,exv do
|
||||
for z=-exh,exh do
|
||||
local node=minetest.get_node_or_nil(vector.add(first_pos, {x=x, y=y, z=z}))
|
||||
if (advtrains.train_collides(node)) then
|
||||
collides=true
|
||||
|
|
Loading…
Reference in New Issue