tgstation/-tg-station — pull request #3633 by Menshin (2014-05-03 22:41:38+00:00)
Title: [RFC] Powernets refactoring

I started by investigating the powernet odd behavior, but finished by commenting/reorganizing/rewriting a large part of the power code...

I had to make design choices for this one, that have to be approved by the community, so, that's just a RFC for now.
This will get a PR if/when the community is ok with the way i've designed cable laying/machine connecting.

I've compiled a little file with the (not so) new powernets behavior/handling, that can be found here : http://www.sendspace.com/file/5nb2mn
Please pardon the guerilla-style Paint illustrations...

The main change is that machines can now only be connected via a node cable on its turf (got rid of the _directwired_ half broken/implemented way of doing)

A quick summary of what was done :
* cleaned, organized and commented a large part of the power code,
* some new procs handling (powernets creation/destruction, cable adding/removing, machines adding/removing, ...)
* new cable laying possibility : if you click in the turf you're standing on, you'll try to lay a node cable in the direction you're facing,
* cleaned lots of oversights that could (and would) leaved empty powernets in the powernets global list
* got rid of the recursive way of propagating networks,
* rewrote the cut_cable and propagate_network procs to correctly updates every connected cables and machines (fix, at last, #1455).

That last one was severely lacking : in fact, each time you cut a cable and there was more than one adjacent cable in a given direction, only the first found was updated (so you'll get cables with null powernet or physically separated cables that were in the same powernet).

There's certainly room for improvement and optimization, but it's working and a good base for anyone wanting to meddle with powernets.