diff options
-rw-r--r-- | car.lua | 40 | ||||
-rw-r--r-- | controller.lua | 18 | ||||
-rw-r--r-- | controllerfw.lua | 97 | ||||
-rw-r--r-- | drive_entity.lua | 10 | ||||
-rw-r--r-- | pilantern.lua | 9 | ||||
-rw-r--r-- | textures/celevator_button_rect.png | bin | 0 -> 574 bytes | |||
-rw-r--r-- | textures/celevator_button_rect_active.png | bin | 0 -> 574 bytes | |||
-rw-r--r-- | textures/celevator_car_switch_panel.png | bin | 0 -> 1761 bytes |
8 files changed, 145 insertions, 29 deletions
@@ -14,7 +14,7 @@ local pieces = { tiles = { "celevator_car_floor.png", "celevator_cabinet_sides.png", - "celevator_car_wallpaper.png^celevator_car_wall_bottom.png", + "celevator_car_wallpaper.png^celevator_car_wall_bottom.png^celevator_car_switch_panel.png", "celevator_cabinet_sides.png", }, }, @@ -350,12 +350,29 @@ for _,def in ipairs(pieces) do if carid == 0 then return end local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) if not carinfo then return end - local event = { - type = "cop", - fields = fields, - player = player:get_player_name(), - } - celevator.controller.run(carinfo.controllerpos,event) + local nname = minetest.get_node(pos).name + if nname == "celevator:car_010" then + local event = { + type = "cop", + fields = fields, + player = player:get_player_name(), + } + celevator.controller.run(carinfo.controllerpos,event) + elseif nname == "celevator:car_000" then + if fields.quit then return end + local name = player:get_player_name() + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then + minetest.chat_send_player(name,"You don't have access to these switches.") + minetest.record_protection_violation(pos,name) + return + end + local event = { + type = "copswitches", + fields = fields, + player = name, + } + celevator.controller.run(carinfo.controllerpos,event) + end end if def._position == "000" then def.on_construct = function(pos) @@ -410,12 +427,3 @@ minetest.register_abm({ end, }) -function celevator.car.updatecop(pos) - local copmeta = minetest.get_meta(pos) - local carid = copmeta:get_int("carid") - if carid == 0 then return end - local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) - if not carinfo then return end - local controllermeta = minetest.get_meta(carinfo.controllerpos) - copmeta:set_string("formspec",controllermeta:get_string("copformspec")) -end diff --git a/controller.lua b/controller.lua index 884f620..b4c36c7 100644 --- a/controller.lua +++ b/controller.lua @@ -467,6 +467,10 @@ function celevator.controller.finish(pos,mem,changedinterrupts) local newpiuparrow = mem.piuparrow local oldpidownarrow = oldmem.pidownarrow local newpidownarrow = mem.pidownarrow + local oldflashfs = oldmem.flash_fs + local newflashfs = mem.flash_fs + local oldflashis = oldmem.flash_is + local newflashis = mem.flash_is if oldpiuparrow ~= newpiuparrow then carinfodirty = true carinfo.piuparrow = newpiuparrow @@ -483,6 +487,17 @@ function celevator.controller.finish(pos,mem,changedinterrupts) celevator.pi.setarrow(pi.pos,"down",newpidownarrow) end end + if oldflashfs ~= newflashfs or oldflashis ~= newflashis then + carinfodirty = true + carinfo.flash_fs = newflashfs + carinfo.flash_is = newflashis + local pis = carinfo.pis + local what = newflashis and "IS" + if newflashfs then what = "FS" end + for _,pi in pairs(pis) do + celevator.pi.flash(pi.pos,what) + end + end local oldlanterns = oldmem.lanterns or {} local newlanterns = mem.lanterns or {} local lanterns = carinfo.lanterns @@ -493,7 +508,8 @@ function celevator.controller.finish(pos,mem,changedinterrupts) end end meta:set_string("copformspec",mem.copformspec) - if mem.copformspec ~= oldmem.copformspec and drivetype then + meta:set_string("switchformspec",mem.switchformspec) + if (mem.copformspec ~= oldmem.copformspec or mem.switchformspec ~= oldmem.switchformspec) and drivetype then minetest.after(0.25,celevator.drives[drivetype].updatecopformspec,drivepos) end meta:set_string("mem",minetest.serialize(mem)) diff --git a/controllerfw.lua b/controllerfw.lua index e879175..4d95aea 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -209,6 +209,10 @@ if event.type == "program" then mem.activefaults = {} mem.faultlog = {} mem.fatalfault = false + mem.fs2sw = "off" + mem.indsw = false + mem.lightsw = true + mem.fansw = true if not mem.params then mem.state = "unconfigured" mem.screenstate = "oobe_welcome" @@ -330,7 +334,7 @@ elseif event.type == "ui" then end elseif mem.screenstate == "status" then for i=1,#mem.params.floornames,1 do - if event.fields[string.format("carcall%d",i)] and (mem.carstate == "normal" or mem.carstate == "test" or mem.carstate == "capture") then + if event.fields[string.format("carcall%d",i)] and (mem.carstate == "normal" or mem.carstate == "test" or mem.carstate == "capture" or mem.carstate == "indep") then mem.carcalls[i] = true elseif event.fields[string.format("upcall%d",i)] and mem.carstate == "normal" and not mem.capturesw then mem.upcalls[i] = true @@ -424,7 +428,7 @@ elseif event.type == "callbutton" and mem.carstate == "normal" then elseif event.iid == "checkopen" then if mem.drive.status.doorstate == "open" then interrupt(0,"opened") - interrupt(nil,"opentimeout") + if mem.carstate == "normal" or mem.carstate == "indep" then interrupt(nil,"opentimeout") end else interrupt(0.2,"checkopen") end @@ -441,7 +445,7 @@ elseif event.iid == "closetimeout" then fault("closetimeout",true) elseif event.type == "cop" then local fields = event.fields - if mem.carstate == "normal" then + if mem.carstate == "normal" or mem.carstate == "indep" then for k,v in pairs(fields) do if string.sub(k,1,7) == "carcall" then local landing = tonumber(string.sub(k,8,-1)) @@ -456,6 +460,21 @@ elseif event.type == "cop" then open() end end +elseif event.type == "copswitches" then + local fields = event.fields + if fields.fanon then + mem.fansw = true + elseif fields.fanoff then + mem.fansw = false + elseif fields.lighton then + mem.lightsw = true + elseif fields.lightoff then + mem.lightsw = false + elseif fields.indon then + mem.indsw = true + elseif fields.indoff then + mem.indsw = false + end end local oldstate = mem.carstate @@ -481,20 +500,44 @@ elseif mem.controllerinspectsw and not mem.cartopinspectsw then mem.dncalls = {} mem.direction = nil if oldstate ~= "mrinspect" then drivecmd({command="estop"}) end +elseif mem.indsw then + if mem.carstate ~= "resync" then mem.carstate = "indep" end + mem.upcalls = {} + mem.dncalls = {} + if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then + mem.carstate = "resync" + gotofloor(getpos()) + elseif oldstate == "normal" and mem.doorstate == "closed" and not (mem.carmotion or juststarted) then + open() + elseif oldstate == "normal" and mem.doorstate == "open" then + interrupt(nil,"close") + end elseif mem.testsw then mem.upcalls = {} mem.dncalls = {} - mem.carstate = "test" + if mem.carstate ~= "resync" then mem.carstate = "test" end + if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then + mem.carstate = "resync" + gotofloor(getpos()) + end elseif mem.capturesw then mem.upcalls = {} mem.dncalls = {} - if not mem.direction then mem.carstate = "capture" end + if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then + mem.carstate = "resync" + gotofloor(getpos()) + elseif mem.carstate ~= "resync" and not mem.direction then + mem.carstate = "capture" + end else if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then mem.carstate = "resync" gotofloor(getpos()) elseif oldstate == "test" or oldstate == "capture" then mem.carstate = "normal" + elseif oldstate == "indep" then + mem.carstate = "normal" + if mem.doorstate == "open" then interrupt(mem.params.doortimer,"close") end end end @@ -503,7 +546,7 @@ if mem.carmotion then if mem.carmotion then interrupt(0.1,"checkdrive") else - if mem.carstate == "normal" then + if mem.carstate == "normal" or mem.carstate == "indep" then mem.carcalls[getpos()] = nil if mem.direction == "up" then mem.upcalls[getpos()] = nil @@ -526,12 +569,20 @@ if mem.carmotion then mem.direction = "up" end elseif mem.carstate == "bfdemand" or mem.carstate == "resync" then - mem.carstate = "normal" + if mem.indsw then + mem.carstate = "indep" + elseif mem.testsw then + mem.carstate = "test" + elseif mem.capturesw then + mem.carstate = "capture" + else + mem.carstate = "normal" + end end end end -if (mem.carstate == "normal" or mem.carstate == "capture" or mem.carstate == "test") and mem.doorstate == "closed" and not mem.carmotion then +if (mem.carstate == "normal" or mem.carstate == "capture" or mem.carstate == "test" or mem.carstate == "indep") and mem.doorstate == "closed" and not mem.carmotion then if mem.direction == "up" then if getnextcallabove("up") then mem.direction = "up" @@ -787,6 +838,9 @@ local arrowenabled = { mem.piuparrow = mem.drive.status.vel > 0 and arrowenabled[mem.carstate] mem.pidownarrow = mem.drive.status.vel < 0 and arrowenabled[mem.carstate] +mem.flash_fs = false +mem.flash_is = mem.carstate == "indep" + mem.lanterns = {} if mem.carstate == "normal" and (mem.doorstate == "open" or mem.doorstate == "opening") then mem.lanterns[getpos()] = mem.direction @@ -819,4 +873,31 @@ elseif copcols == 2 then end mem.copformspec = mem.copformspec..string.format("image_button[%f,%f;1,1;%s;close;%s;false;false;%s]",dcxp,coprows*1.25+1.5,unlitimg,minetest.formspec_escape(">|<"),litimg) +mem.switchformspec = "formspec_version[7]size[8,10]" +local fs2ontex = (mem.fs2sw == "on") and "celevator_button_rect_active.png" or "celevator_button_rect.png" +local fs2holdtex = (mem.fs2sw == "hold") and "celevator_button_rect_active.png" or "celevator_button_rect.png" +local fs2offtex = (mem.fs2sw == "off" or not mem.fs2sw) and "celevator_button_rect_active.png" or "celevator_button_rect.png" +mem.switchformspec = mem.switchformspec..string.format("image_button[1.5,1.5;1.5,1;%s;fs2on;ON;false;false;celevator_button_rect_active.png]",fs2ontex) +mem.switchformspec = mem.switchformspec..string.format("image_button[1.5,2.5;1.5,1;%s;fs2hold;HOLD;false;false;celevator_button_rect_active.png]",fs2holdtex) +mem.switchformspec = mem.switchformspec..string.format("image_button[1.5,3.5;1.5,1;%s;fs2off;OFF;false;false;celevator_button_rect_active.png]",fs2offtex) +mem.switchformspec = mem.switchformspec.."label[1.6,4.75;FIRE SVC]" + +local indontex = mem.indsw and "celevator_button_rect_active.png" or "celevator_button_rect.png" +local indofftex = (not mem.indsw) and "celevator_button_rect_active.png" or "celevator_button_rect.png" +mem.switchformspec = mem.switchformspec..string.format("image_button[4.5,1.5;1.5,1;%s;indon;ON;false;false;celevator_button_rect_active.png]",indontex) +mem.switchformspec = mem.switchformspec..string.format("image_button[4.5,3.5;1.5,1;%s;indoff;OFF;false;false;celevator_button_rect_active.png]",indofftex) +mem.switchformspec = mem.switchformspec.."label[4.6,4.75;IND SVC]" + +local lightontex = mem.lightsw and "celevator_button_rect_active.png" or "celevator_button_rect.png" +local lightofftex = (not mem.lightsw) and "celevator_button_rect_active.png" or "celevator_button_rect.png" +mem.switchformspec = mem.switchformspec..string.format("image_button[1.5,5.5;1.5,1;%s;lighton;ON;false;false;celevator_button_rect_active.png]",lightontex) +mem.switchformspec = mem.switchformspec..string.format("image_button[1.5,7.5;1.5,1;%s;lightoff;OFF;false;false;celevator_button_rect_active.png]",lightofftex) +mem.switchformspec = mem.switchformspec.."label[1.6,8.75;CAR LIGHT]" + +local fanontex = mem.fansw and "celevator_button_rect_active.png" or "celevator_button_rect.png" +local fanofftex = (not mem.fansw) and "celevator_button_rect_active.png" or "celevator_button_rect.png" +mem.switchformspec = mem.switchformspec..string.format("image_button[4.5,5.5;1.5,1;%s;fanon;ON;false;false;celevator_button_rect_active.png]",fanontex) +mem.switchformspec = mem.switchformspec..string.format("image_button[4.5,7.5;1.5,1;%s;fanoff;OFF;false;false;celevator_button_rect_active.png]",fanofftex) +mem.switchformspec = mem.switchformspec.."label[4.6,8.75;CAR FAN]" + return pos,mem,changedinterrupts diff --git a/drive_entity.lua b/drive_entity.lua index b651538..d5b8287 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -484,6 +484,9 @@ function celevator.drives.entity.estop(pos) celevator.drives.entity.entitiestonodes(handles) stopbuzz(pos) motorsound(pos,"idle") + local carid = meta:get_int("carid") + if carid ~= 0 then celevator.drives.entity.sheavetonode(carid) end + minetest.after(0.25,celevator.drives.entity.updatecopformspec,pos) end @@ -800,7 +803,8 @@ function celevator.drives.entity.updatecopformspec(drivepos) if carid == 0 then return end local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) if not carinfo then return end - local formspec = minetest.get_meta(carinfo.controllerpos):get_string("copformspec") + local copformspec = minetest.get_meta(carinfo.controllerpos):get_string("copformspec") + local switchformspec = minetest.get_meta(carinfo.controllerpos):get_string("switchformspec") local origin = minetest.string_to_pos(drivemeta:get_string("origin")) if not origin then minetest.log("error","[celevator] [entity drive] Invalid origin for drive at "..minetest.pos_to_string(drivepos)) @@ -814,7 +818,9 @@ function celevator.drives.entity.updatecopformspec(drivepos) local piecepos = minetest.get_position_from_hash(hash) local piece = minetest.get_node(piecepos) if piece.name == "celevator:car_010" then - minetest.get_meta(piecepos):set_string("formspec",formspec) + minetest.get_meta(piecepos):set_string("formspec",copformspec) + elseif piece.name == "celevator:car_000" then + minetest.get_meta(piecepos):set_string("formspec",switchformspec) end end end diff --git a/pilantern.lua b/pilantern.lua index 28ffd44..909c68f 100644 --- a/pilantern.lua +++ b/pilantern.lua @@ -31,6 +31,11 @@ minetest.register_entity("celevator:incar_pi_entity",{ 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) + if carinfo.flash_is and os.time()%2 == 0 then + text = " IS" + elseif carinfo.flash_fs and os.time()%2 == 0 then + text = " FS" + end local etex = celevator.pi.generatetexture(text,carinfo.piuparrow,carinfo.pidownarrow,false,true) self.object:set_properties({textures = {etex}}) else @@ -79,10 +84,10 @@ function celevator.pi.updatedisplay(pos) local islantern = minetest.get_item_group(minetest.get_node(pos).name,"_celevator_lantern") == 1 local etex = celevator.pi.generatetexture(text,uparrow,downarrow,islantern) if flash_fs then - if flashtimer then etex = celevator.pi.generatetexture(" FS",uparrow,downarrow) end + if flashtimer then etex = celevator.pi.generatetexture(" FS",uparrow,downarrow,islantern) end entity:set_properties({_flash_fs = true,_flash_is = false,}) elseif flash_is then - if flashtimer then etex = celevator.pi.generatetexture(" IS",uparrow,downarrow) end + if flashtimer then etex = celevator.pi.generatetexture(" IS",uparrow,downarrow,islantern) end entity:set_properties({_flash_fs = false,_flash_is = true,}) else entity:set_properties({_flash_fs = false,_flash_is = false,}) diff --git a/textures/celevator_button_rect.png b/textures/celevator_button_rect.png Binary files differnew file mode 100644 index 0000000..e5513a7 --- /dev/null +++ b/textures/celevator_button_rect.png diff --git a/textures/celevator_button_rect_active.png b/textures/celevator_button_rect_active.png Binary files differnew file mode 100644 index 0000000..710ece6 --- /dev/null +++ b/textures/celevator_button_rect_active.png diff --git a/textures/celevator_car_switch_panel.png b/textures/celevator_car_switch_panel.png Binary files differnew file mode 100644 index 0000000..c399068 --- /dev/null +++ b/textures/celevator_car_switch_panel.png |