Closed stilnat closed 8 months ago
SolarPanel prefab is missing Network Object script. I forgot to add it in my PR, please do so in this one.
Fix conflicts
Ok. It's about ready for one of the coders to do a review on this.
Make sure to do gitbook documentation under "Systems" if you haven't already. Then link it on the PR.
@cosmiccoincidence just waiting for Iamteapot final review before writing doc
Summary
Provide a first implementation of the electricity system, mostly the foundation to build on it, but also provide a few implementation, including, working batteries, basic infinite energy generator, functionnal cables, light turning off and on based on power availability.
generator sound under CC0 found here : https://freesound.org/people/qubodup/sounds/189896/
PR checklist
Pictures/Videos)
Testing
Networking checklist
Changes
The electric system relies on the QuickGraph package, which allow to use some graph objects and apply some graph algorithms. It's relevant to decide what's connected to what. We're using an undirected graph since, at least in this first iteration, there's no sense of direction of the power, we only care if two things are connected, or not.
The graph represent the set of all circuits on the map. A vertice in the graph consists of coordinates, tilelayer and direction (so 4 elements) of a given electric thing (cable, lamp, generator). An edge in the graph represents a connection between two electric things.
When adding a new electric element, the electric system uses some connector script from the tile system to decide if this element is connected to anything. If it is, then it's going to add a new edge for each connection, expanding the graph. If it's connected to nothing, it's still going to add a new vertice, representing the disconnected element.
A circuit consists of a set of relevant element all connected together. A single vertice with no edge is as such considered to be a circuit as well.
When changing anything in the disposition of electrical elements on the map, the graph update, and compute back all circuits. Computing circuits is not that expensive, it's using a graph traversing algorithm, which execute in O(V+E) complexity, V for the number of vertices and E the number of edges. The complexity grows pretty much only linearly with the number of electric things, which should be very scalable.
Related issues/PRs
TODO