ff to current state #6

Merged
kistaro merged 27 commits from pyrex/chameleonic:main into main 2022-12-19 07:03:33 +00:00
Showing only changes of commit 37db329b08 - Show all commits

View File

@ -1199,8 +1199,11 @@ end
function _vec_ang_diff(x0,y0,x1,y1) function _vec_ang_diff(x0,y0,x1,y1)
local ang0=atan2(x0,y0) local ang0=atan2(x0,y0)
local ang1=atan2(x1,y1) local ang1=atan2(x1,y1)
return _ang_diff(ang0,ang1)
end
return (ang1-ang0+0.5)%1-0.5 function _ang_diff(ang0,ang1)
return abs((ang1-ang0+0.5)%1-0.5)
end end
function sum_distance(x,y,z) function sum_distance(x,y,z)
@ -1387,8 +1390,8 @@ function rope:_tug(hypothetically)
local touched={} local touched={}
for i=#ancs-1,2,-1 do for i=#ancs-1,2,-1 do
local ops_before_trash=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1]) local ops_before_trash=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1],ancs[i-2])
local ops_after_trash=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i]) local ops_after_trash=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i],ancs[i+1])
local ops_to_do={} local ops_to_do={}
if #ops_before_trash>0 then if #ops_before_trash>0 then
ops_to_do=ops_before_trash ops_to_do=ops_before_trash
@ -1474,7 +1477,7 @@ function rope:_tug(hypothetically)
(dmx!=0 and sgn0(pull_dx)!=dmx) or (dmx!=0 and sgn0(pull_dx)!=dmx) or
(dmy!=0 and sgn0(pull_dy)!=dmy) or (dmy!=0 and sgn0(pull_dy)!=dmy) or
abs(_vec_ang_diff(pull_anc.x\8-mx0,pull_anc.y\8-my0,dmx,dmy)) > 0.125 or _vec_ang_diff(pull_anc.x\8-mx0,pull_anc.y\8-my0,dmx,dmy) > 0.125 or
sgn0(mx0-mxa)!= sgn0(mx0-mxa)!=
sgn0(mx0+dmx-mxa) or sgn0(mx0+dmx-mxa) or
@ -1503,12 +1506,17 @@ function rope:_tug(hypothetically)
end end
function rope:_calc_push( function rope:_calc_push(
an,a0,a1 an,a0,a1,af
) )
local ops={} local ops={}
if (an==nil) return ops if (an==nil) return ops
local pull_ang=atan2(
a0.x\8 - an.x\8,
a0.y\8-an.y\8
)
if a0.x==a1.x then if a0.x==a1.x then
-- no far side applying pressure?
local y0,y1=_mnmx(a0.y,a1.y) local y0,y1=_mnmx(a0.y,a1.y)
local my0,my1,smy=(y0+1)\8,(y1-1)\8,1 local my0,my1,smy=(y0+1)\8,(y1-1)\8,1
if a0.y>a1.y then if a0.y>a1.y then
@ -1518,10 +1526,16 @@ function rope:_calc_push(
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
local needs_good_pull=af==nil or af.x>=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.5)>=0.125) return {}
-- push left -- push left
mx=(a0.x-1)\8 mx=(a0.x-1)\8
dmx=-1 dmx=-1
elseif a0.x%8==7 and a0.x<an.x-7 then elseif a0.x%8==7 and a0.x<an.x-7 then
local needs_good_pull=af==nil or af.x<=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.0)>=0.125) return {}
-- push right -- push right
mx=(a0.x+1)\8 mx=(a0.x+1)\8
dmx=1 dmx=1
@ -1544,11 +1558,17 @@ function rope:_calc_push(
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
local needs_good_pull=af==nil or af.x>=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.75)>=0.125) return {}
-- push up -- push up
my=(a0.y-1)\8 my=(a0.y-1)\8
dmy=-1 dmy=-1
elseif a0.y%8==7 and a0.y<an.y-6 then elseif a0.y%8==7 and a0.y<an.y-6 then
local needs_good_pull=af==nil or af.x>=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.25)>=0.125) return {}
-- push down -- push down
my=(a0.y+1)\8 my=(a0.y+1)\8
dmy=1 dmy=1