diff options
-rw-r--r-- | controllerfw.lua | 18 | ||||
-rw-r--r-- | dispatcherfw.lua | 17 |
2 files changed, 29 insertions, 6 deletions
diff --git a/controllerfw.lua b/controllerfw.lua index b509df8..47f21f0 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -833,12 +833,26 @@ elseif mem.fs1switch then end end elseif mem.drive.status.vel < 0 and mem.drive.status.apos < gettarget(mem.params.mainlanding or 1) then - for i=1,getpos(),1 do + for i=getpos(),1,-1 do if mem.drive.status.neareststop > gettarget(i) and mem.drive.status.dpos < gettarget(i) then gotofloor(i) break end end + elseif mem.drive.status.vel < 0 and mem.drive.status.dpos < gettarget(mem.params.mainlanding or 1) and mem.drive.status.apos > gettarget(mem.params.mainlanding or 1) then + for i=(mem.params.mainlanding or 1),1,-1 do + if mem.drive.status.neareststop > gettarget(i) and mem.drive.status.dpos < gettarget(i) then + gotofloor(i) + break + end + end + elseif mem.drive.status.vel > 0 and mem.drive.status.dpos > gettarget(mem.params.mainlanding or 1) and mem.drive.status.apos < gettarget(mem.params.mainlanding or 1) then + for i=(mem.params.mainlanding or 1),#mem.params.floornames,1 do + if mem.drive.status.neareststop < gettarget(i) and mem.drive.status.dpos > gettarget(i) then + gotofloor(i) + break + end + end elseif getpos() ~= (mem.params.mainlanding or 1) then if not (mem.carmotion or juststarted) then if mem.doorstate == "closed" then @@ -847,7 +861,7 @@ elseif mem.fs1switch then close() end end - elseif mem.doorstate == "closed" then + elseif mem.doorstate == "closed" or mem.doorstate == "closing" then if not (mem.carmotion or juststarted) then open() end diff --git a/dispatcherfw.lua b/dispatcherfw.lua index aac7e07..bb609d5 100644 --- a/dispatcherfw.lua +++ b/dispatcherfw.lua @@ -169,7 +169,15 @@ local function gettarget(floor) return target end -local function predictnextstop(carid,startpos,direction,carcalls,upcalls,dncalls) +local function predictnextstop(carid,startpos,direction,carcalls,upcalls,dncalls,leaving) + if leaving then + local vel = mem.carstatus[carid].vel + if vel > 0 then + startpos = startpos+1 + elseif vel < 0 then + startpos = startpos-1 + end + end if direction == "up" then if getnextcallabove(carid,"up",startpos,carcalls,upcalls,dncalls) then return getnextcallabove(carid,"up",startpos,carcalls,upcalls,dncalls),"up" @@ -216,7 +224,7 @@ local function estimatetraveltime(carid,src,dest) return estimate end -local function buildstopsequence(carid,startfloor,direction,target,targetdir) +local function buildstopsequence(carid,startfloor,direction,target,targetdir,leaving) local carcalls = cartorealfloor(carid,mem.carstatus[carid].carcalls) local upcalls = cartorealfloor(carid,mem.carstatus[carid].upcalls) local dncalls = cartorealfloor(carid,mem.carstatus[carid].dncalls) @@ -235,7 +243,7 @@ local function buildstopsequence(carid,startfloor,direction,target,targetdir) end repeat local src = carpos - carpos,direction = predictnextstop(carid,carpos,direction,carcalls,upcalls,dncalls) + carpos,direction = predictnextstop(carid,carpos,direction,carcalls,upcalls,dncalls,leaving) carcalls[carpos] = nil if direction == "up" then upcalls[carpos] = nil @@ -251,7 +259,8 @@ local function buildstopsequence(carid,startfloor,direction,target,targetdir) end local function calculateeta(carid,floor,direction) - local sequence = buildstopsequence(carid,getpos(carid),mem.carstatus[carid].direction,floor,direction) + local leaving = (getpos(carid) ~= getdpos(carid)) and (getpos(carid) == floor) + local sequence = buildstopsequence(carid,getpos(carid),mem.carstatus[carid].direction,floor,direction,leaving) local doorstate = mem.carstatus[carid].doorstate local doortimes = { closed = 0, |