diff options
author | cheapie <no-email-for-you@example.com> | 2024-05-10 21:00:30 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2024-05-10 21:00:30 -0500 |
commit | 6c908698d72cdac9fbc85a7e3d168fd3f431e2e3 (patch) | |
tree | 833548ad00b85e943cc564fef7dec91476aeca9e | |
parent | 5ac4571337aea7ea2f9153a3138c3d1db1ff981f (diff) | |
download | celevator-6c908698d72cdac9fbc85a7e3d168fd3f431e2e3.tar celevator-6c908698d72cdac9fbc85a7e3d168fd3f431e2e3.tar.gz celevator-6c908698d72cdac9fbc85a7e3d168fd3f431e2e3.tar.bz2 celevator-6c908698d72cdac9fbc85a7e3d168fd3f431e2e3.tar.xz celevator-6c908698d72cdac9fbc85a7e3d168fd3f431e2e3.zip |
Add nudging
Timer can be edited from the parameters menu, entering 0 disables nudging
-rw-r--r-- | controller.lua | 4 | ||||
-rw-r--r-- | controllerfw.lua | 50 | ||||
-rw-r--r-- | docs/file_sources | 5 | ||||
-rw-r--r-- | doors.lua | 42 | ||||
-rw-r--r-- | drive_entity.lua | 4 | ||||
-rw-r--r-- | pilantern.lua | 2 | ||||
-rw-r--r-- | sounds/celevator_nudge.ogg | bin | 0 -> 209062 bytes |
7 files changed, 83 insertions, 24 deletions
diff --git a/controller.lua b/controller.lua index 184da36..2e47c98 100644 --- a/controller.lua +++ b/controller.lua @@ -437,7 +437,7 @@ function celevator.controller.finish(pos,mem,changedinterrupts) elseif command.command == "open" then minetest.after(0.25,celevator.drives[drivetype].movedoors,drivepos,"open") elseif command.command == "close" then - celevator.drives[drivetype].movedoors(drivepos,"close") + celevator.drives[drivetype].movedoors(drivepos,"close",command.nudge) elseif command.command == "resetfault" then celevator.drives[drivetype].resetfault(drivepos) elseif command.command == "pibeep" then @@ -505,6 +505,8 @@ function celevator.controller.finish(pos,mem,changedinterrupts) celevator.pi.flash(pi.pos,what) end end + carinfo.flash_blank = mem.flash_blank + if mem.flash_blank ~= oldmem.flash_blank then carinfodirty = true end local oldlanterns = oldmem.lanterns or {} local newlanterns = mem.lanterns or {} local lanterns = carinfo.lanterns diff --git a/controllerfw.lua b/controllerfw.lua index 47f21f0..0dbc48d 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -193,13 +193,20 @@ local function open() interrupt(0.2,"checkopen") interrupt(10,"opentimeout") interrupt(nil,"closetimeout") + if mem.nudging then + if mem.carstate == "normal" then + interrupt(0,"nudge") + else + mem.nudging = false + end + end end -local function close() +local function close(nudge) mem.doorstate = "closing" - drivecmd({command = "close"}) + drivecmd({command = "close",nudge = nudge}) interrupt(0.2,"checkclosed") - interrupt(10,"closetimeout") + interrupt((nudge and 30 or 10),"closetimeout") interrupt(nil,"opentimeout") end @@ -214,6 +221,7 @@ if type(mem.groupdncalls) ~= "table" then mem.groupdncalls = {} end if type(mem.swingupcalls) ~= "table" then mem.swingupcalls = {} end if type(mem.swingdncalls) ~= "table" then mem.swingdncalls = {} end if mem.params and not mem.params.carcallsecurity then mem.params.carcallsecurity = {} end +if mem.params and not mem.params.nudgetimer then mem.params.nudgetimer = 30 end if event.type == "program" then mem.carstate = "uninit" @@ -254,6 +262,7 @@ if event.type == "program" then groupmode = "simplex", mainlanding = 1, carcallsecurity = {}, + nudgetimer = 30, } end elseif event.type == "ui" then @@ -359,6 +368,10 @@ elseif event.type == "ui" then if contractspeed and contractspeed >= 0.1 and contractspeed <= 20 then mem.params.contractspeed = contractspeed end + local nudgetimer = tonumber(event.fields.nudgetimer) + if nudgetimer and nudgetimer >= 0 and nudgetimer <= 3600 then + mem.params.nudgetimer = nudgetimer + end local mainlanding = tonumber(event.fields.mainlanding) if mainlanding and mainlanding >= 1 and mainlanding <= #mem.params.floorheights then mem.params.mainlanding = math.floor(mainlanding) @@ -528,7 +541,7 @@ elseif event.type == "callbutton" and mem.carstate == "normal" then end elseif mem.direction == event.dir and mem.doorstate == "open" then interrupt(mem.params.doortimer,"close") - elseif mem.direction == event.dir and mem.doorstate == "closing" then + elseif mem.direction == event.dir and mem.doorstate == "closing" and not mem.nudging then open() end elseif event.iid == "checkopen" then @@ -537,6 +550,9 @@ elseif event.iid == "checkopen" then if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" or mem.carstate == "fs2" or mem.carstate == "fs2hold" then interrupt(nil,"opentimeout") end + if mem.carstate == "normal" and not mem.interrupts.nudge and mem.params.nudgetimer > 0 then + interrupt(mem.params.nudgetimer,"nudge") + end else interrupt(0.2,"checkopen") end @@ -544,6 +560,8 @@ elseif event.iid == "checkclosed" then if mem.drive.status.doorstate == "closed" then interrupt(0,"closed") interrupt(nil,"closetimeout") + interrupt(nil,"nudge") + mem.nudging = false else interrupt(0.2,"checkclosed") end @@ -569,7 +587,7 @@ elseif event.type == "cop" then if v and landing and landing >= 1 and landing <= #mem.params.floorheights and secok then if getpos() == landing then if mem.carstate == "normal" or mem.carstate == "indep" then - if mem.doorstate == "closing" then + if mem.doorstate == "closing" and not mem.nudging then open() elseif mem.doorstate == "open" then interrupt(mem.params.doortimer,"close") @@ -718,7 +736,7 @@ elseif event.type == "remotemsg" then elseif event.channel == "carcall" and mem.carstate == "normal" then mem.carcalls[event.msg] = true end -elseif event.type == "lightcurtain" then +elseif event.type == "lightcurtain" and not mem.nudging then if mem.carstate == "normal" or mem.carstate == "indep" then if mem.doorstate == "closing" then open() @@ -726,6 +744,13 @@ elseif event.type == "lightcurtain" then interrupt(mem.params.doortimer,"close") end end +elseif event.iid == "nudge" and mem.carstate == "normal" then + mem.nudging = true + if mem.doorstate == "open" then + close(true) + elseif mem.doorstate == "opening" then + interrupt(1,"nudge") + end end local oldstate = mem.carstate @@ -922,6 +947,12 @@ else end end +if mem.carstate == "normal" and oldstate ~= "normal" and mem.doorstate ~= "closed" and mem.params.nudgetimer > 0 and not mem.interrupts.nudge then + interrupt(mem.params.nudgetimer,"nudge") +elseif mem.carstate ~= "normal" and oldstate == "normal" then + interrupt(nil,"nudge") +end + if mem.carmotion then mem.carmotion = (mem.drive.status.vel ~= 0) or juststarted if mem.carmotion then @@ -966,7 +997,10 @@ if mem.carmotion then mem.swingupcalls[1] = nil mem.groupupcalls[1] = nil end - if (mem.carstate ~= "fs1" or getpos() == (mem.params.mainlanding or 1)) and mem.carstate ~= "fs2" and mem.carstate ~= "fs2hold" then open() end + if (mem.carstate ~= "fs1" or getpos() == (mem.params.mainlanding or 1)) and mem.carstate ~= "fs2" and mem.carstate ~= "fs2hold" then + open() + mem.nudging = false + end if mem.carstate == "fs1" and getpos() ~= (mem.params.mainlanding or 1) then gotofloor(mem.params.mainlanding or 1) end @@ -1263,6 +1297,7 @@ elseif mem.screenstate == "parameters" then fs(string.format("field[1,3;3,1;doortimer;Door Dwell Timer;%0.1f]",mem.params.doortimer)) fs(string.format("field[1,5;3,1;contractspeed;Contract Speed (m/s);%0.1f]",mem.params.contractspeed)) fs(string.format("field[1,7;3,1;mainlanding;Main Landing;%d]",mem.params.mainlanding or 1)) + fs(string.format("field[4.5,3;3,1;nudgetimer;Nudging Timer (0 = None);%0.1f]",mem.params.nudgetimer)) fs("style[resetdoors,resetcontroller;bgcolor=#DD3333]") fs("button[12,1;3,1;resetdoors;Reset Doors]") fs("button[12,2.5;3,1;resetcontroller;Reset Controller]") @@ -1357,6 +1392,7 @@ mem.pidownarrow = mem.drive.status.vel < 0 and arrowenabled[mem.carstate] mem.flash_fs = (mem.carstate == "fs1" or mem.carstate == "fs2" or mem.carstate == "fs2hold") mem.flash_is = mem.carstate == "indep" +mem.flash_blank = mem.nudging mem.lanterns = {} if mem.carstate == "normal" and (mem.doorstate == "open" or mem.doorstate == "opening") then diff --git a/docs/file_sources b/docs/file_sources index b5c6d34..e4c02bb 100644 --- a/docs/file_sources +++ b/docs/file_sources @@ -34,3 +34,8 @@ Edited by cheapie. Originally from "transformer at night.wav" by ideaph on Freesound, originally licensed under CC0. https://freesound.org/people/ideaph/sounds/641208/ Edited by cheapie. + +* celevator_nudge.ogg +Originally from "Buzz Buzzer Buzzing Sound Effect" by deleted_user_7146007 on Freesound, originally licensed under CC0. +https://freesound.org/people/deleted_user_7146007/sounds/383352/ +Edited by cheapie. @@ -290,7 +290,7 @@ function celevator.doors.hwopen(pos,drivepos) end end -function celevator.doors.hwclose(pos,drivepos) +function celevator.doors.hwclose(pos,drivepos,nudge) local hwdoors_moving = minetest.deserialize(celevator.storage:get_string("hwdoors_moving")) or {} local hash = minetest.hash_node_position(pos) if hwdoors_moving[hash] then @@ -302,7 +302,7 @@ function celevator.doors.hwclose(pos,drivepos) local fdir = minetest.fourdir_to_dir(celevator.get_node(pos).param2) local carpos = vector.add(pos,fdir) if celevator.get_node(carpos).name == "celevator:car_000" then - celevator.doors.carclose(carpos) + celevator.doors.carclose(carpos,nudge) end local data = minetest.deserialize(pmeta:get_string("data")) if not data then return end @@ -312,6 +312,7 @@ function celevator.doors.hwclose(pos,drivepos) data.direction = "close" data.time = 0 data.drivepos = drivepos + data.nudging = nudge local erefs = celevator.drives.entity.nodestoentities(data.positions,"celevator:hwdoor_moving") local foffset = vector.multiply(data.opendir,2) local soffset = data.opendir @@ -359,13 +360,15 @@ function celevator.doors.hwstep(dtime) hwdoors_moving[hash] = nil end elseif data.direction == "close" then - data.time = data.time+(0.66*dtime) + local speed = 0.66 + if data.nudging then speed = 0.2 end + data.time = data.time+(speed*dtime) local vel = math.sin(data.time) for i=1,3,1 do - celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel*-0.66)) + celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel*-speed)) end for i=4,6,1 do - celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel/2*-0.66)) + celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel/2*-speed)) end if data.time >= math.pi then for i=1,6,1 do @@ -435,13 +438,15 @@ function celevator.doors.carstep(dtime) cardoors_moving[hash] = nil end elseif data.direction == "close" then - data.time = data.time+(0.66*dtime) + local speed = 0.66 + if data.nudging then speed = 0.2 end + data.time = data.time+(speed*dtime) local vel = math.sin(data.time) for i=1,3,1 do - celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel*-0.66)) + celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel*-speed)) end for i=4,6,1 do - celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel/2*-0.66)) + celevator.doors.erefs[hash][i]:set_velocity(vector.multiply(data.opendir,vel/2*-speed)) end if data.time >= math.pi then for _,ref in ipairs(celevator.doors.erefs[hash]) do @@ -570,7 +575,7 @@ function celevator.doors.caropen(pos) end end -function celevator.doors.carclose(pos) +function celevator.doors.carclose(pos,nudge) local cardoors_moving = minetest.deserialize(celevator.storage:get_string("cardoors_moving")) or {} local hash = minetest.hash_node_position(pos) if cardoors_moving[hash] then @@ -594,11 +599,20 @@ function celevator.doors.carclose(pos) erefs[i]:set_pos(vector.add(erefs[i]:get_pos(),soffset)) end celevator.doors.erefs[hash] = erefs - data.soundhandle = minetest.sound_play("celevator_door_close",{ - pos = pos, - gain = 0.3, - max_hear_distance = 10 - }) + if nudge then + data.soundhandle = minetest.sound_play("celevator_nudge",{ + pos = pos, + gain = 0.75, + max_hear_distance = 10 + }) + else + data.soundhandle = minetest.sound_play("celevator_door_close",{ + pos = pos, + gain = 0.3, + max_hear_distance = 10 + }) + end + data.nudging = nudge cardoors_moving[hash] = data celevator.storage:set_string("cardoors_moving",minetest.serialize(cardoors_moving)) end diff --git a/drive_entity.lua b/drive_entity.lua index 2b048d8..728aa47 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -632,7 +632,7 @@ function celevator.drives.entity.getstatus(pos,call2) end end -function celevator.drives.entity.movedoors(drivepos,direction) +function celevator.drives.entity.movedoors(drivepos,direction,nudge) local drivehash = minetest.hash_node_position(drivepos) local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {} local drivemeta = celevator.get_meta(drivepos) @@ -657,7 +657,7 @@ function celevator.drives.entity.movedoors(drivepos,direction) celevator.doors.hwopen(hwdoorpos,drivepos) drivemeta:set_string("doorstate","opening") elseif direction == "close" and celevator.get_node(hwdoorpos).name == "celevator:hwdoor_placeholder" then - celevator.doors.hwclose(hwdoorpos,drivepos) + celevator.doors.hwclose(hwdoorpos,drivepos,nudge) drivemeta:set_string("doorstate","closing") end end diff --git a/pilantern.lua b/pilantern.lua index 386ec94..75de06f 100644 --- a/pilantern.lua +++ b/pilantern.lua @@ -37,6 +37,8 @@ minetest.register_entity("celevator:incar_pi_entity",{ text = " IS" elseif carinfo.flash_fs and os.time()%2 == 0 then text = " FS" + elseif carinfo.flash_blank and os.time()%2 == 0 then + text = " " end local etex = celevator.pi.generatetexture(text,carinfo.piuparrow,carinfo.pidownarrow,false,true) self.object:set_properties({textures = {etex}}) diff --git a/sounds/celevator_nudge.ogg b/sounds/celevator_nudge.ogg Binary files differnew file mode 100644 index 0000000..b9309a1 --- /dev/null +++ b/sounds/celevator_nudge.ogg |