summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2024-04-04 20:57:56 -0500
committercheapie <no-email-for-you@example.com>2024-04-04 20:57:56 -0500
commit12c3ce32dc9d6111b54a981cf39cb22f57c3800e (patch)
tree428312546d30fc52d08f2a01f5e49a1e3f19ff08
parent0759be7c0a41170a92a99e53a5728efc5767bd5e (diff)
downloadcelevator-12c3ce32dc9d6111b54a981cf39cb22f57c3800e.tar
celevator-12c3ce32dc9d6111b54a981cf39cb22f57c3800e.tar.gz
celevator-12c3ce32dc9d6111b54a981cf39cb22f57c3800e.tar.bz2
celevator-12c3ce32dc9d6111b54a981cf39cb22f57c3800e.tar.xz
celevator-12c3ce32dc9d6111b54a981cf39cb22f57c3800e.zip
Make in-car PI work
-rw-r--r--car.lua3
-rw-r--r--controller.lua10
-rw-r--r--drive_entity.lua17
-rw-r--r--pilantern.lua20
4 files changed, 43 insertions, 7 deletions
diff --git a/car.lua b/car.lua
index 5ce2983..39b4733 100644
--- a/car.lua
+++ b/car.lua
@@ -347,7 +347,7 @@ for _,def in ipairs(pieces) do
minetest.register_node("celevator:car_"..def._position,def)
end
-function celevator.car.spawncar(origin,yaw)
+function celevator.car.spawncar(origin,yaw,carid)
local right = vector.rotate_around_axis(vector.new(1,0,0),vector.new(0,1,0),yaw)
local back = vector.rotate_around_axis(vector.new(0,0,1),vector.new(0,1,0),yaw)
local up = vector.new(0,1,0)
@@ -363,6 +363,7 @@ function celevator.car.spawncar(origin,yaw)
param2 = minetest.dir_to_fourdir(minetest.yaw_to_dir(yaw)),
}
minetest.set_node(pos,node)
+ if carid then minetest.get_meta(pos):set_int("carid",carid) end
end
end
end
diff --git a/controller.lua b/controller.lua
index cc4f68d..a36dee1 100644
--- a/controller.lua
+++ b/controller.lua
@@ -411,6 +411,7 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
local meta = minetest.get_meta(pos)
local carid = meta:get_int("carid")
local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid)))
+ local carinfodirty = false
if not carinfo then
minetest.log("error","[celevator] [controller] Bad car info for controller at "..minetest.pos_to_string(pos))
return
@@ -453,6 +454,8 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
local oldpitext = oldmem.pifloor or "--"
local newpitext = mem.pifloor or "--"
if oldpitext ~= newpitext then
+ carinfodirty = true
+ carinfo.pitext = newpitext
local pis = carinfo.pis
for _,pi in pairs(pis) do
celevator.pi.settext(pi.pos,newpitext)
@@ -463,12 +466,16 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
local oldpidownarrow = oldmem.pidownarrow
local newpidownarrow = mem.pidownarrow
if oldpiuparrow ~= newpiuparrow then
+ carinfodirty = true
+ carinfo.piuparrow = newpiuparrow
local pis = carinfo.pis
for _,pi in pairs(pis) do
celevator.pi.setarrow(pi.pos,"up",newpiuparrow)
end
end
if oldpidownarrow ~= newpidownarrow then
+ carinfodirty = true
+ carinfo.pidownarrow = newpidownarrow
local pis = carinfo.pis
for _,pi in pairs(pis) do
celevator.pi.setarrow(pi.pos,"down",newpidownarrow)
@@ -501,6 +508,9 @@ function celevator.controller.finish(pos,mem,changedinterrupts)
celevator.storage:set_string("controller_equeue",minetest.serialize(celevator.controller.equeue))
celevator.controller.run(pos,event)
end
+ if carinfodirty then
+ celevator.storage:set_string(string.format("car%d",carid),minetest.serialize(carinfo))
+ end
end
end
diff --git a/drive_entity.lua b/drive_entity.lua
index 4d861ce..8c9f27c 100644
--- a/drive_entity.lua
+++ b/drive_entity.lua
@@ -162,7 +162,7 @@ function celevator.drives.entity.nodestoentities(nodes,ename)
return refs
end
-function celevator.drives.entity.entitiestonodes(refs)
+function celevator.drives.entity.entitiestonodes(refs,carid)
local ok = true
for _,eref in ipairs(refs) do
local pos = eref:get_pos()
@@ -174,6 +174,7 @@ function celevator.drives.entity.entitiestonodes(refs)
}
minetest.set_node(pos,node)
eref:remove()
+ if carid then minetest.get_meta(pos):set_int("carid",carid) end
elseif pos and eref:get_luaentity().name == "celevator:incar_pi_entity" then
pos = vector.new(pos.x,math.floor(pos.y+0.5),pos.z)
eref:set_pos(pos)
@@ -198,6 +199,7 @@ function celevator.drives.entity.step(dtime)
table.remove(entitydrives_running,i)
else
local meta = minetest.get_meta(pos)
+ local carid = meta:get_int("carid")
local state = meta:get_string("state")
if not (state == "running" or state == "start" or state == "fakerunning") then
table.remove(entitydrives_running,i)
@@ -249,10 +251,10 @@ function celevator.drives.entity.step(dtime)
if dremain < 0.05 then
vel = 0
meta:set_string("state","stopped")
- local ok = celevator.drives.entity.entitiestonodes(handles)
+ local ok = celevator.drives.entity.entitiestonodes(handles,carid)
if not ok then
local carparam2 = meta:get_int("carparam2")
- celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)))
+ celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)),carid)
end
apos = math.floor(apos+0.5)
elseif dremain < 0.2 then
@@ -280,7 +282,7 @@ function celevator.drives.entity.step(dtime)
vel = 0
meta:set_string("state","stopped")
local carparam2 = meta:get_int("carparam2")
- celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)))
+ celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)),carid)
apos = math.floor(apos+0.5)
elseif dremain < 0.2 then
vel = 0.2
@@ -464,8 +466,15 @@ local function updatecarpos(pos)
if drivemeta:get_string("state") == "uninit" then
drivemeta:set_string("origin",minetest.pos_to_string(carpos))
drivemeta:set_string("state","stopped")
+ drivemeta:set_int("carid",carid)
end
end
+ local caryaw = minetest.dir_to_yaw(minetest.fourdir_to_dir(minetest.get_node(carpos).param2))
+ local carnodes = celevator.drives.entity.gathercar(carpos,caryaw)
+ for hash in pairs(carnodes) do
+ local carmeta = minetest.get_meta(minetest.get_position_from_hash(hash))
+ carmeta:set_int("carid",carid)
+ end
else
meta:set_string("infotext","No car found! Punch to try again")
end
diff --git a/pilantern.lua b/pilantern.lua
index 8986209..28ffd44 100644
--- a/pilantern.lua
+++ b/pilantern.lua
@@ -20,10 +20,26 @@ minetest.register_entity("celevator:incar_pi_entity",{
physical = false,
collisionbox = {0,0,0,0,0,0,},
textures = {"celevator_transparent.png",},
- _flashtimer = 0,
- _machinepos = "",
static_save = false,
},
+ on_step = function(self)
+ local pos = self.object:get_pos()
+ local props = self.object:get_properties()
+ if props.breath_max and props.breath_max ~= 0 then
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",props.breath_max)))
+ if not carinfo then return end
+ local text = carinfo.pitext or "--"
+ if string.len(text) < 3 then text = string.rep(" ",3-string.len(text))..text end
+ text = string.sub(text,1,3)
+ local etex = celevator.pi.generatetexture(text,carinfo.piuparrow,carinfo.pidownarrow,false,true)
+ self.object:set_properties({textures = {etex}})
+ else
+ local carpos = vector.round(pos)
+ local carmeta = minetest.get_meta(carpos)
+ local carid = carmeta:get_int("carid")
+ if carid > 0 then self.object:set_properties({breath_max=carid}) end
+ end
+ end,
})
function celevator.pi.removeentity(pos)