Page 1 of 1

Method to prevent certain automatic power pole connections

Posted: Mon Aug 30, 2021 11:40 pm
by Xorimuth
When a power pole is placed it is automatically connected to some nearby poles. In my mod I want a pole to only automatically connect to certain other types of poles. I do this by listening to the on_build/revive events and then disconnecting the pole from certain neighbours. You can see my implementation here: https://github.com/tburrows13/PowerOver ... lua#L9-L20

My problem is that the electric networks are momentarily joined so they are 'polluted' for 5 seconds (the minimum precision time for accessing usage data). I can see several ways of mitigating this (in rough order of preference):
  • Add a way to list compatible entities in the power pole prototype
  • Don't momentarily merge electric networks if they are disconnected again on the same tick
  • Add a prototype flag to disable automatic connections entirely
(For related reading, see viewtopic.php?f=28&t=94959&p=536012#p536012, which I've been told wouldn't be easy to implement into the API)

Re: Method to prevent certain automatic power pole connections

Posted: Sat Aug 31, 2024 11:46 am
by TBC_x
I am trying to optimize power networks (many disconnected power networks) by merging them all into single big network, because the stats are being (likely) collected regardless of whether the network has any producers or consumers.

This solved UPS issues of many networks but now I need to prevent the player from abusing this large network. I have to detect if the player is building in the vicinity of this power network so I can disconnect cross-surface connections. And the only way to detect it is, right now, to check if the new power pole would have connected to the power network with on_pre_build event, which I would use to duplicate (in an inferior way) the search for would-be connecting poles.

What I would need is to receive an event right before cable connection is made so I can tinker with the connections and avoid merging player's networks with the inactive one.

This mostly applies to power poles used decoratively.