2026-10-28 15:39:06 +02:00
|
|
|
extends RefCounted
|
|
|
|
|
static func resolve(g):
|
|
|
|
|
var actors=[{"node":g.player,"radius":0.40,"weight":1.0}]
|
|
|
|
|
for s in g.souls:
|
|
|
|
|
var radius=1.35 if s.id==g.working and g.development.selected>0 else (0.53 if s.kind in [0,3] else 0.38)
|
|
|
|
|
actors.append({"node":s.node,"radius":radius,"weight":0.0 if s.entering or s.id==g.working else 0.65})
|
2026-10-28 23:04:47 +02:00
|
|
|
for imp in g.life.imps:actors.append({"node":imp.root,"radius":0.34,"weight":1.0})
|
2026-10-28 15:39:06 +02:00
|
|
|
for burn in g.life.burns:
|
|
|
|
|
if is_instance_valid(burn.root):actors.append({"node":burn.root,"radius":0.52,"weight":0.0})
|
|
|
|
|
for iteration in range(4):
|
|
|
|
|
for i in range(actors.size()):
|
|
|
|
|
for j in range(i+1,actors.size()):
|
|
|
|
|
var a=actors[i];var b=actors[j]
|
|
|
|
|
var delta=a.node.position-b.node.position;delta.y=0
|
|
|
|
|
var minimum=a.radius+b.radius+0.04
|
|
|
|
|
var distance=delta.length()
|
|
|
|
|
var total=a.weight+b.weight
|
|
|
|
|
if distance>=minimum or total<=0:continue
|
|
|
|
|
var axis=delta/distance if distance>0.0001 else Vector3.RIGHT
|
|
|
|
|
var correction=axis*(minimum-distance)
|
|
|
|
|
a.node.position+=correction*a.weight/total
|
|
|
|
|
b.node.position-=correction*b.weight/total
|
|
|
|
|
# Keep mobile actors on the walkable floor after separation.
|
|
|
|
|
for a in actors:
|
|
|
|
|
if a.weight<=0:continue
|
|
|
|
|
if a.node==g.player or not g.souls.any(func(s):return s.node==a.node):
|
|
|
|
|
resolve_equipment(g,a.node,a.radius)
|
|
|
|
|
a.node.position.x=clampf(a.node.position.x,-7.3,7.2)
|
|
|
|
|
a.node.position.z=clampf(a.node.position.z,-4.8,5.7)
|
|
|
|
|
|
|
|
|
|
static func resolve_equipment(g,node,radius):
|
|
|
|
|
if g.development.selected==0:return
|
|
|
|
|
var extents=[Vector2.ZERO,Vector2(1.05,1.7),Vector2(1.55,1.15),Vector2(1.14,1.12)][g.development.selected]
|
|
|
|
|
var p=Vector2(node.position.x-g.STATION.x,node.position.z-g.STATION.z)
|
|
|
|
|
var nearest=Vector2(clampf(p.x,-extents.x,extents.x),clampf(p.y,-extents.y,extents.y))
|
|
|
|
|
var delta=p-nearest
|
|
|
|
|
if delta.length_squared()>0.00001:
|
|
|
|
|
if delta.length()<radius:p=nearest+delta.normalized()*(radius+.015)
|
|
|
|
|
else:
|
|
|
|
|
var dx=extents.x-abs(p.x);var dz=extents.y-abs(p.y)
|
|
|
|
|
if dx<dz:p.x=(extents.x+radius+.015)*(1 if p.x>=0 else -1)
|
|
|
|
|
else:p.y=(extents.y+radius+.015)*(1 if p.y>=0 else -1)
|
|
|
|
|
node.position.x=g.STATION.x+p.x;node.position.z=g.STATION.z+p.y
|