diff options
author | cheapie <no-email-for-you@example.com> | 2024-04-17 17:56:01 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2024-04-17 17:56:01 -0500 |
commit | 19d69394b61ed9370d79c5efbd1b23fb8c5eac6a (patch) | |
tree | e6a01748e34913ea59684898f8a17d1633ad27dc /drive_entity.lua | |
parent | a0f604f950742a540b1e427bf190cfc79ca977f8 (diff) | |
download | celevator-19d69394b61ed9370d79c5efbd1b23fb8c5eac6a.tar celevator-19d69394b61ed9370d79c5efbd1b23fb8c5eac6a.tar.gz celevator-19d69394b61ed9370d79c5efbd1b23fb8c5eac6a.tar.bz2 celevator-19d69394b61ed9370d79c5efbd1b23fb8c5eac6a.tar.xz celevator-19d69394b61ed9370d79c5efbd1b23fb8c5eac6a.zip |
Allow changing destination in-flight
This allows new calls entered while the car is moving to be serviced before the original destination, provided they are in the correct direction, will be reached before the original destination, and the car can stop soon enough.
Diffstat (limited to 'drive_entity.lua')
-rw-r--r-- | drive_entity.lua | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/drive_entity.lua b/drive_entity.lua index e1e448b..6378725 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -463,7 +463,6 @@ minetest.register_globalstep(celevator.drives.entity.step) function celevator.drives.entity.moveto(pos,target) local meta = minetest.get_meta(pos) - if meta:get_string("state") ~= "stopped" then return end local carid = minetest.get_meta(pos):get_int("carid") local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) if not (carinfo and carinfo.machinepos) then return end @@ -477,27 +476,40 @@ function celevator.drives.entity.moveto(pos,target) meta:set_string("fault","outofbounds") return end - meta:set_string("dpos",tostring(target)) - meta:set_string("state","start") - meta:set_string("startpos",meta:get_string("apos")) - local hash = minetest.hash_node_position(pos) - local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {} - local running = false - for _,dhash in ipairs(entitydrives_running) do - if hash == dhash then - running = true - break - end - end - if not running then - table.insert(entitydrives_running,hash) - celevator.storage:set_string("entitydrives_running",minetest.serialize(entitydrives_running)) - --Controller needs to see something so it knows the drive is running + if meta:get_string("state") ~= "stopped" then local apos = tonumber(meta:get_string("apos")) - if apos and apos > target then - meta:set_string("vel","-0.0001") + local vel = tonumber(meta:get_string("vel")) + if vel > 0 then + if target < apos+(vel*2) then return end + elseif vel < 0 then + if target > apos-(vel*-2) then return end else - meta:set_string("vel","0.0001") + return + end + end + meta:set_string("dpos",tostring(target)) + if meta:get_string("state") == "stopped" then + meta:set_string("state","start") + meta:set_string("startpos",meta:get_string("apos")) + local hash = minetest.hash_node_position(pos) + local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {} + local running = false + for _,dhash in ipairs(entitydrives_running) do + if hash == dhash then + running = true + break + end + end + if not running then + table.insert(entitydrives_running,hash) + celevator.storage:set_string("entitydrives_running",minetest.serialize(entitydrives_running)) + --Controller needs to see something so it knows the drive is running + local apos = tonumber(meta:get_string("apos")) + if apos and apos > target then + meta:set_string("vel","-0.0001") + else + meta:set_string("vel","0.0001") + end end end end @@ -540,7 +552,7 @@ function celevator.drives.entity.getstatus(pos,call2) local node = minetest.get_node(pos) if node.name == "ignore" and not call2 then minetest.forceload_block(pos,true) - return celevator.drives.null.get_status(pos,true) + return celevator.drives.entity.get_status(pos,true) elseif node.name ~= "celevator:drive" then minetest.log("error","[celevator] [entity drive] Could not load drive status at "..minetest.pos_to_string(pos)) return {fault = "metaload"} @@ -554,6 +566,7 @@ function celevator.drives.entity.getstatus(pos,call2) ret.state = meta:get_string("state") ret.doorstate = meta:get_string("doorstate") ret.fault = meta:get_string("fault") + ret.neareststop = ret.apos+(ret.vel*2) if ret.fault == "" then ret.fault = nil end return ret end |