Fix misc other rope bugs

This commit is contained in:
Pyrex 2022-12-18 16:07:15 -08:00
parent 97e580e7db
commit d2e1e9274c

View File

@ -800,7 +800,25 @@ function rope:update()
self.latch_frame=10
end
if (not is_busy) self:_make_consistent()
if (self.latch==nil) self:destroy() return
if
self.latch!=nil and
self.latch.rec!=nil
then
self:drag_src(
self.latch.rec.px+self.latch.px_offset,
self.latch.rec.py+self.latch.py_offset
)
if #self.latch.rec.todo==0 then
if self.latch.rec.dead==true then
self:destroy()
end
end
end
if (not is_busy) self:_tidy_up_gen()
elseif self.state.name=="destroy" then -- destroy
self.state.frame+=1
if (self.state.frame>=5) self.state={name="done"}
@ -814,34 +832,6 @@ function rope:destroy()
self.state={name="destroy",frame=0}
end
function rope:_make_consistent()
if (self.latch==nil) self:destroy() return
if
self.latch!=nil and
self.latch.rec!=nil
then
self:drag_src(
self.latch.rec.px+self.latch.px_offset,
self.latch.rec.py+self.latch.py_offset
)
if #self.latch.rec.todo==0 then
if self.latch.rec.dead==true then
self:destroy()
end
end
end
self:_tidy_up_gen()
for i=0,#self.ancs do
local a0=self:_anc(i)
local a1=self:_anc(i+1)
if not self:_can_stretch(a0,a1) then
self:destroy()
end
end
end
function rope:continue_cast()
local dx,dy=self.state.dx,self.state.dy
local x0=self.src.x
@ -909,11 +899,12 @@ function rope:draw()
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
end
end
for i,p in ipairs(self.ancs) do
for i=0,#self.ancs+1 do
p=self:_anc(i)
local c=12
if (p.dirty) c=13
rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c)
print(p.id..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9)
print(tostr(p.id)..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9)
end
for _,p in pairs(level._anch) do
pset(p.x,p.y,11)
@ -982,6 +973,7 @@ function rope:_tidy_up_gen()
end
if (invalid) self:make_dirty()
local busy=self:busy()
if (not self:latched()) return
if (not self.dirty) return
@ -993,7 +985,7 @@ function rope:_tidy_up_gen()
local anc=self:_anc(a)
if anc.dirty then
anc.seen=true
if self[f](self,a) then
if self[f](self,a,busy) then
settled=false anc.changed=true
end
end
@ -1042,6 +1034,16 @@ function rope:_tidy_up_gen()
if (settled) break
end
if (self:busy()) return
for i=0,#self.ancs do
local a0=self:_anc(i)
local a1=self:_anc(i+1)
if not self:_can_stretch(a0,a1) then
self:destroy()
end
end
self.dirty=false
end
@ -1105,7 +1107,7 @@ function rope:_find_touched_anchors(i)
return false
end
function rope:_elide_point(i)
function rope:_elide_point(i,busy)
if (i<=0) return false
if (#self.ancs<i) return false
@ -1114,10 +1116,10 @@ function rope:_elide_point(i)
local a2=self:_anc(i+1)
local level_anc=level:point_anchor(a1.x,a1.y)
if _point_eq(a0,a1) or _point_eq(a1,a2) or level_anc==nil then
if _point_eq(a0,a1) or _point_eq(a1,a2) or (not busy and level_anc==nil) then
-- do it unconditionally
else
if _linedist(a0,a1,a2) < 0.1 then
if _linedist(a0,a1,a2) < 0.01 then
return false
end
@ -1136,8 +1138,8 @@ function rope:_elide_point(i)
end
deli(self.ancs,i)
--self:_anc(i-1).dirty=true
--self:_anc(i).dirty=true
a0.dirty=true a0.changed=true
a2.dirty=true a2.changed=true
return true
end
@ -1345,10 +1347,10 @@ function rope:tug_orientxy()
end
function rope:tug()
self:_make_consistent()
self:_tidy_up_gen()
if (not self:latched()) return
self:_tug()
self:_make_consistent()
self:_tidy_up_gen()
end
function rope:_tug(hypothetically)
@ -1361,25 +1363,43 @@ function rope:_tug(hypothetically)
add(self.all_ops,o)
end
local ops_to_do={}
for o in all(ops) do
if not level:mcoll(o.mx,o.my) then
-- great!
else
local crate=level:get_crate(o.mx,o.my)
if crate==nil or touched[_mix(o.mx,o.my)] then
break
local find_all=function(lhs,rhs,di)
local ops2do={}
for i=lhs,rhs,di do
local o=ops[i]
if not level:mcoll(o.mx,o.my) then
-- great!
else
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
local crate=level:get_crate(o.mx,o.my)
if crate==nil or touched[_mix(o.mx,o.my)] then
break
else
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
break
end
end
add(ops2do,o)
end
add(ops_to_do,o)
end
return ops2do
end
local ops_before_trash=find_all(1,#ops,1)
local ops_to_do={}
local corners={}
if #ops_before_trash>0 then
ops_to_do=ops_before_trash
corners[i-1]=true
else
ops_to_do=find_all(#ops,1,-1)
corners[i]=true
end
local do_all=#ops==#ops_to_do
ops=ops_to_do
if (do_all) corners[i-1]=true corners[i]=true
if #ops>0 then
if (hypothetically) return ancs,i-1
@ -1391,8 +1411,6 @@ function rope:_tug(hypothetically)
o.mx,o.my,dmx,dmy
)
end
local move_up_to=i
if (do_all) move_up_to=i-1
for node=ancs[i-1].ix,ancs[i].ix do
local anc=self:_anc(node)
local x0,y0=anc.x,anc.y
@ -1409,7 +1427,7 @@ function rope:_tug(hypothetically)
end}
end
local dmxh,dmyh=dmx,dmy
if (node<ancs[move_up_to].ix) dmxh,dmyh=0,0
if (not corners[node]) dmxh,dmyh=0,0
anc.todo={
{},
upd(x0+dmxh*2,y0+dmyh*2),
@ -1431,16 +1449,22 @@ function rope:_tug(hypothetically)
local dmx,dmy=
sgn0(latch.dx),
sgn0(latch.dy)
local lanc=ancs[2]
local obj_anc=ancs[1]
local pull_anc=ancs[2]
local pull_dx=pull_anc.x-obj_anc.x
local pull_dy=pull_anc.y-obj_anc.y
local mx0=latch.rec.mx
local my0=latch.rec.my
local mxa=(lanc.x+dmx)\8
local mya=(lanc.y+dmy)\8
local mxa=(pull_anc.x+dmx)\8
local mya=(pull_anc.y+dmy)\8
local too_far=false
if
(dmx!=0 and sgn0(pull_dx)!=dmx) or
(dmy!=0 and sgn0(pull_dy)!=dmy) or
sgn0(mx0-mxa)!=
sgn0(mx0+dmx-mxa) or
@ -1461,7 +1485,7 @@ function rope:_tug(hypothetically)
dmx,dmy
)
-- be busy for 4 ticks while the crate moves
self:_anc(0).todo={{},{},{},{}}
self:_anc(0).todo={{},{},{},{},{}}
end
end
@ -1513,7 +1537,7 @@ function rope:_calc_push(
my=(a0.y-1)\8
dmy=-1
elseif a0.y%8==7 and a0.y<an.y-3 then
elseif a0.y%8==7 and a0.y<an.y-6 then
-- push down
my=(a0.y+1)\8
dmy=1
@ -1733,9 +1757,9 @@ __map__
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c00000000001c000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0000000000000000000000000000000c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c00000000001c0000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0000000000000000000000000000410000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
@ -1743,8 +1767,8 @@ __map__
3d00000c4f00003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c00000c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c00410c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__sfx__
01280000050550c05511055180551d05500000000000000000055070550c0550f055130550f0550c0550705501055080550d055140551905500000000000000000055070550f0551305518055130550f0550c055
0128000000000000001f0001f055200551f0551d055180551b055000000000000000000000000000000000000000000000000001b0551d0551b05519055140551805500000000000000000000000000000000000