More rope refactors
This commit is contained in:
parent
16aba34869
commit
581e345e31
116
chameleonic.p8
116
chameleonic.p8
@ -309,6 +309,7 @@ function level:reanchor(remove)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if (player.rope!=nil) player.rope:make_dirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
function level:win_at(mx,my)
|
function level:win_at(mx,my)
|
||||||
@ -772,12 +773,6 @@ end
|
|||||||
|
|
||||||
function rope:done()
|
function rope:done()
|
||||||
return self.state.name=="done"
|
return self.state.name=="done"
|
||||||
--[[
|
|
||||||
return self.latch_frame>=2 and (
|
|
||||||
self.latch==nil or
|
|
||||||
self.under_destruction
|
|
||||||
)
|
|
||||||
]]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:busy()
|
function rope:busy()
|
||||||
@ -800,8 +795,8 @@ function rope:update()
|
|||||||
elseif self.state.name=="destroy" then -- destroy
|
elseif self.state.name=="destroy" then -- destroy
|
||||||
self.state.frame+=1
|
self.state.frame+=1
|
||||||
if (self.state.frame>=5) self.state={name="done"}
|
if (self.state.frame>=5) self.state={name="done"}
|
||||||
else --
|
else
|
||||||
assert(false, "todo")
|
-- done state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -818,6 +813,8 @@ function rope:_make_consistent()
|
|||||||
|
|
||||||
if (self.latch==nil) self:destroy() return
|
if (self.latch==nil) self:destroy() return
|
||||||
|
|
||||||
|
self:_tidy_up_gen()
|
||||||
|
|
||||||
if
|
if
|
||||||
self.latch!=nil and
|
self.latch!=nil and
|
||||||
self.latch.rec!=nil
|
self.latch.rec!=nil
|
||||||
@ -830,18 +827,27 @@ function rope:_make_consistent()
|
|||||||
if #self.latch.rec.todo==0 then
|
if #self.latch.rec.todo==0 then
|
||||||
if self.latch.rec.dead==true then
|
if self.latch.rec.dead==true then
|
||||||
self:destroy()
|
self:destroy()
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local invalid=false
|
||||||
for i=0,#self.ancs do
|
for i=0,#self.ancs do
|
||||||
local a0=self:_anc(i)
|
local a0=self:_anc(i)
|
||||||
local a1=self:_anc(i+1)
|
local a1=self:_anc(i+1)
|
||||||
if not self:_can_stretch(a0,a1) then
|
if not self:_can_stretch(a0,a1) then
|
||||||
self:destroy()
|
invalid=true
|
||||||
return
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if (invalid) self:make_dirty() 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
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:continue_cast()
|
function rope:continue_cast()
|
||||||
@ -875,7 +881,7 @@ function rope:_reindex()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function rope:draw()
|
function rope:draw()
|
||||||
local points=self:_anchors_simplified()
|
local points,highlight=self:_tug(true)
|
||||||
if (self.state.name=="done") return
|
if (self.state.name=="done") return
|
||||||
local perc_to_show=1.0
|
local perc_to_show=1.0
|
||||||
if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/5)^2
|
if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/5)^2
|
||||||
@ -902,14 +908,19 @@ function rope:draw()
|
|||||||
local coef=min(len_here/dist_base,1.0)
|
local coef=min(len_here/dist_base,1.0)
|
||||||
dx,dy=dx*coef,dy*coef
|
dx,dy=dx*coef,dy*coef
|
||||||
|
|
||||||
linefill(x,y,x+0.25*dx,y+0.25*dy,1.0,8)
|
local color=8
|
||||||
linefill(x+0.25*dx,y+0.25*dy,x+1*dx,y+1*dy,0.5,8)
|
if (highlight==i) color=14
|
||||||
linefill(x+0.9*dx,y+0.9*dy,x+dx,y+dy,1.0,8)
|
|
||||||
circfill(x+dx+0.5,y+dy+0.5,1.0,8)
|
linefill(x,y,x+0.25*dx,y+0.25*dy,1.0,color)
|
||||||
|
linefill(x+0.25*dx,y+0.25*dy,x+1*dx,y+1*dy,0.5,color)
|
||||||
|
linefill(x+0.9*dx,y+0.9*dy,x+dx,y+dy,1.0,color)
|
||||||
|
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i,p in ipairs(self.ancs) do
|
for i,p in ipairs(self.ancs) do
|
||||||
rectfill(p.x-1,p.y-1,p.x+1,p.y+1,12)
|
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(p.id..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9)
|
||||||
end
|
end
|
||||||
for _,p in pairs(level._anch) do
|
for _,p in pairs(level._anch) do
|
||||||
@ -957,6 +968,13 @@ function rope:drag(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rope:make_dirty()
|
||||||
|
for a=0,#self.ancs+1 do
|
||||||
|
self:_anc(a).dirty=true
|
||||||
|
end
|
||||||
|
self.dirty=true
|
||||||
|
end
|
||||||
|
|
||||||
function rope:_tidy_up_gen()
|
function rope:_tidy_up_gen()
|
||||||
if (not self:latched()) return
|
if (not self:latched()) return
|
||||||
if (not self.dirty) return
|
if (not self.dirty) return
|
||||||
@ -1012,6 +1030,7 @@ function rope:_tidy_up_gen()
|
|||||||
for a=0,#self.ancs+1,1 do
|
for a=0,#self.ancs+1,1 do
|
||||||
local anc=self:_anc(a)
|
local anc=self:_anc(a)
|
||||||
if (anc.seen) anc.dirty=anc.changed
|
if (anc.seen) anc.dirty=anc.changed
|
||||||
|
if (anc.dirty) settled=false
|
||||||
end
|
end
|
||||||
|
|
||||||
if (settled) break
|
if (settled) break
|
||||||
@ -1111,6 +1130,8 @@ function rope:_elide_point(i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
deli(self.ancs,i)
|
deli(self.ancs,i)
|
||||||
|
--self:_anc(i-1).dirty=true
|
||||||
|
--self:_anc(i).dirty=true
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1324,7 +1345,7 @@ function rope:tug()
|
|||||||
self:_make_consistent()
|
self:_make_consistent()
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:_tug()
|
function rope:_tug(hypothetically)
|
||||||
local ancs=self:_anchors_simplified()
|
local ancs=self:_anchors_simplified()
|
||||||
local touched={}
|
local touched={}
|
||||||
|
|
||||||
@ -1334,24 +1355,28 @@ function rope:_tug()
|
|||||||
add(self.all_ops,o)
|
add(self.all_ops,o)
|
||||||
end
|
end
|
||||||
|
|
||||||
local can_do=true
|
local ops_to_do={}
|
||||||
for o in all(ops) do
|
for o in all(ops) do
|
||||||
if not level:mcoll(o.mx,o.my) then
|
if not level:mcoll(o.mx,o.my) then
|
||||||
-- great!
|
-- great!
|
||||||
else
|
else
|
||||||
local crate=level:get_crate(o.mx,o.my)
|
local crate=level:get_crate(o.mx,o.my)
|
||||||
if crate==nil or touched[_mix(o.mx,o.my)] then
|
if crate==nil or touched[_mix(o.mx,o.my)] then
|
||||||
can_do=false
|
break
|
||||||
else
|
else
|
||||||
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
|
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
|
||||||
can_do=false
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
add(ops_to_do,o)
|
||||||
end
|
end
|
||||||
if (not can_do) break
|
|
||||||
end
|
end
|
||||||
|
local do_all=#ops==#ops_to_do
|
||||||
|
ops=ops_to_do
|
||||||
|
|
||||||
|
if #ops>0 then
|
||||||
|
if (hypothetically) return ancs,i-1
|
||||||
|
|
||||||
if can_do and #ops>=1 then
|
|
||||||
local dmx,dmy=ops[1].dmx,ops[1].dmy
|
local dmx,dmy=ops[1].dmx,ops[1].dmy
|
||||||
for o in all(ops) do
|
for o in all(ops) do
|
||||||
touched[_mix(o.mx,o.my)]=true
|
touched[_mix(o.mx,o.my)]=true
|
||||||
@ -1360,6 +1385,8 @@ function rope:_tug()
|
|||||||
o.mx,o.my,dmx,dmy
|
o.mx,o.my,dmx,dmy
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
local move_up_to=i
|
||||||
|
if (do_all) move_up_to=i-1
|
||||||
for node=ancs[i-1].ix,ancs[i].ix do
|
for node=ancs[i-1].ix,ancs[i].ix do
|
||||||
local anc=self:_anc(node)
|
local anc=self:_anc(node)
|
||||||
local x0,y0=anc.x,anc.y
|
local x0,y0=anc.x,anc.y
|
||||||
@ -1369,16 +1396,19 @@ function rope:_tug()
|
|||||||
if force or not level:pcoll(x,y) then
|
if force or not level:pcoll(x,y) then
|
||||||
s.x=x
|
s.x=x
|
||||||
s.y=y
|
s.y=y
|
||||||
self.dirty=true
|
|
||||||
end
|
end
|
||||||
|
s.dirty=true
|
||||||
|
self.dirty=true
|
||||||
return true
|
return true
|
||||||
end}
|
end}
|
||||||
end
|
end
|
||||||
|
local dmxh,dmyh=dmx,dmy
|
||||||
|
if (node<ancs[move_up_to].ix) dmxh,dmyh=0,0
|
||||||
anc.todo={
|
anc.todo={
|
||||||
{},
|
{},
|
||||||
upd(x0+dmx*2,y0+dmy*2),
|
upd(x0+dmxh*2,y0+dmyh*2),
|
||||||
upd(x0+dmx*7,y0+dmy*7),
|
upd(x0+dmxh*7,y0+dmyh*7),
|
||||||
upd(x0+dmx*8,y0+dmy*8),
|
upd(x0+dmxh*8,y0+dmyh*8),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
for node=ancs[i-1].ix-1,ancs[i].ix+1 do
|
for node=ancs[i-1].ix-1,ancs[i].ix+1 do
|
||||||
@ -1389,7 +1419,7 @@ function rope:_tug()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local latch=self.latch
|
local latch=self.latch
|
||||||
if (latch==nil) return
|
if (latch==nil) return ancs,nil
|
||||||
|
|
||||||
if latch.el=="crate" then
|
if latch.el=="crate" then
|
||||||
local dmx,dmy=
|
local dmx,dmy=
|
||||||
@ -1418,6 +1448,8 @@ function rope:_tug()
|
|||||||
not touched[_mix(mx0,my0)] and
|
not touched[_mix(mx0,my0)] and
|
||||||
level:can_move(false,mx0,my0,dmx,dmy,1,0)
|
level:can_move(false,mx0,my0,dmx,dmy,1,0)
|
||||||
then
|
then
|
||||||
|
if (hypothetically) return ancs,1
|
||||||
|
|
||||||
level:tug_crate(
|
level:tug_crate(
|
||||||
mx0,my0,
|
mx0,my0,
|
||||||
dmx,dmy
|
dmx,dmy
|
||||||
@ -1426,6 +1458,8 @@ function rope:_tug()
|
|||||||
self:_anc(0).todo={{},{},{},{}}
|
self:_anc(0).todo={{},{},{},{}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return ancs,nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:_calc_push(
|
function rope:_calc_push(
|
||||||
@ -1435,7 +1469,11 @@ function rope:_calc_push(
|
|||||||
|
|
||||||
if a0.x==a1.x then
|
if a0.x==a1.x then
|
||||||
local y0,y1=_mnmx(a0.y,a1.y)
|
local y0,y1=_mnmx(a0.y,a1.y)
|
||||||
local my0,my1=(y0+1)\8,(y1-1)\8
|
local my0,my1,smy=(y0+1)\8,(y1-1)\8,1
|
||||||
|
if a0.y>a1.y then
|
||||||
|
my0,my1=my1,my0
|
||||||
|
smy=-smy
|
||||||
|
end
|
||||||
|
|
||||||
local mx,dmx
|
local mx,dmx
|
||||||
if a0.x%8==0 and a0.x>an.x+7 then
|
if a0.x%8==0 and a0.x>an.x+7 then
|
||||||
@ -1450,14 +1488,18 @@ function rope:_calc_push(
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
for my=my0,my1,1 do
|
for my=my0,my1,smy do
|
||||||
add(ops,{mx=mx,my=my,dmx=dmx,dmy=0})
|
add(ops,{mx=mx,my=my,dmx=dmx,dmy=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if a0.y==a1.y then
|
if a0.y==a1.y then
|
||||||
local x0,x1=_mnmx(a0.x,a1.x)
|
local x0,x1=_mnmx(a0.x,a1.x)
|
||||||
local mx0,mx1=(x0+1)\8,(x1-1)\8
|
local mx0,mx1,smx=(x0+1)\8,(x1-1)\8,1
|
||||||
|
if a0.x>a1.x then
|
||||||
|
mx0,mx1=mx1,mx0
|
||||||
|
smx=-smx
|
||||||
|
end
|
||||||
|
|
||||||
local my,dmy
|
local my,dmy
|
||||||
if a0.y%8==0 and a0.y>an.y+6 then
|
if a0.y%8==0 and a0.y>an.y+6 then
|
||||||
@ -1473,7 +1515,7 @@ function rope:_calc_push(
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
for mx=mx0,mx1,1 do
|
for mx=mx0,mx1,smx do
|
||||||
add(ops,{mx=mx,my=my,dmx=0,dmy=dmy})
|
add(ops,{mx=mx,my=my,dmx=0,dmy=dmy})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1686,15 +1728,15 @@ __map__
|
|||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0100000000001c000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c00000000001c000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c00000000000000120100000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0000000000000c00000000000000120100000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
3d00000c4f00003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
__sfx__
|
__sfx__
|
||||||
|
Loading…
Reference in New Issue
Block a user