Skip to content

fix(connect_entities): return the pole network that was just connected - #428

Open
hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/connect-poles-return-own-network
Open

hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/connect-poles-return-own-network

Conversation

@hashbender

Copy link
Copy Markdown

Problem

connect_entities(a, b, Prototype.SmallElectricPole) (or medium or big poles) can return the ElectricityGroup of a different network elsewhere on the map. With one network built in each quadrant:

for x, y in [(30, 30), (-30, -30), (30, -30), (-30, 30)]:
    g = connect_entities(Position(x=x, y=y), Position(x=x + 5, y=y), Prototype.SmallElectricPole)
# the last call returns ElectricityGroup(poles=[(x=30.5, y=-29.5), (x=33.5, y=-30.5)]): the third network

An agent reading group.poles or the group id then reasons about the wrong network.

Root cause

  • _process_power_groups (connect_entities/client.py:1003-1017) returns self.get_entities({poles}, source_pos), which uses the default radius=1000 and so lists every pole network nearby.
  • _connect_pair_of_waypoints returns connection[0] (:266): whichever network the map search finds first.
  • The pipe and wall paths (_process_pipe_groups, _process_groups) already pick the group at source_pos.

Fix

  • Return the group that holds a pole this connection placed.
  • If none were placed (already connected), return the group at source_pos.
  • Otherwise keep the old list.

Testing

Run against a Factorio 2.0.73 headless server:

  • New test_connect_poles_returns_own_network in tests/connect/test_connect_poles.py fails on main (the 4th connection returns the 3rd network) and passes with the fix.
  • Whole file with the fix: 13 passed, 1 failed. The failure, test_connect_power_poles_without_blocking_mining_drill, fails the same way on main and with the fix (it needs 52 poles and the fixture gives 50 on this map). Not related to this change.
  • ruff 0.11.13 format/check clean.

🤖 Generated with Claude Code

_process_power_groups returned get_entities(poles, source_pos), which uses
the default radius of 1000 and so lists every pole network nearby, and
_connect_pair_of_waypoints returns connection[0]. A pole connection could
therefore return the ElectricityGroup of an unrelated network elsewhere on
the map.

Pick the group holding the poles the connection placed (or, if none were
placed, the group at the source position), as the pipe and wall paths
already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant