Electric Pole like system

Hey guys!

I’m struggling quite a bit trying to make an “electric-pole-like” system.
What I want to achieve is the same as the said system:
I have an actor generating energy and “pole-actors” making that energy flow between them.

Problem is when I have those poles disconnected with each other.

Looking at picture B, I have pole 2 and 3 still generating energy and I don’t know how to handle this.

Can anyone help me please?
Much appreciated

Is this a BP, can we see it?

You need to let a pole have energy only when

  1. It is connected to the generator

or

  1. It is connected to a pole that is (… ) to the generator.

Let’s say I have a boolean “ConnectedToGenerator”.
In picture A, I have all of the variables set to True, but if I disconnect 1 from 2 (like in picture B), how can I set both 2 and 3 to False?

Subsequent communications between BPs is the problem:

since 2 communicates with 1 and “sees” that it is disconnected but also it communicates with 3, it “sees” that it is connected and so it thinks it is indeed connected to the generator when it is not.

It’s kinda hard to explain exactely my problem though :confused:
It seems easy but it is not, or at least not for me.

I have no BPs to show as I tried a LOT of times with no success so I need to have a real solution before starting up again.

It’s a really complex problem, I can tell you that. I struggled with a very similar one once, and I might be able to help you, but I need to know a few conditions:

  1. Can multiple Poles be connected to a single Generator at the same time, or are they only powered in a chain?

  2. Can there be more than one generator in a level to be able to ultimately power one Pole from two or more Generator at the same time?

  3. How exactly are Poles get powered up? Is it based on their proximity to a power source or are there some other event that turn them on?

Like this. A node only has power if it is connected to the generator or it is connected to another node with power.

So it never looks further than it’s neighbour.

This works.

That’s why I couldn’t figure that out then.
To answer your questions:

  1. Every generator can have up to 4 connections, same as the poles.

  2. Yes there can be multiple generators in a level and multiple generators can “energize” a pole.
    Also generators can be connected to each other.

  3. Ideally I’d like generators to send power to a conductor (an electrical cable for example) which then sends power to the pole which then sends that power to all other connections.
    But I don’t mind an easier or more straight solution if it solves the problem.

Cheers

Okay, frankly, the more I think of it, the more difficult it gets. The closest thing to this was implemented in recent Trine 4, but idk how they did it.

One thing that comes to mind is that you can recalculate everything every time a disconnection happens. Like, if you disconnect one pole, you set every pole’s Connected bool to False and immediately recalculate starting from the generators. If you don’t have hundreds of poles, it won’t be noticeable.

Because if you want to do it the “proper” way and only disable the ones that have to be disabled, it might be even more expensive than that.

Sorry I couldn’t help more.

I think you have to be very clear about exactly how you want it to work, otherwise you’ll never get there. Also, what can you limit? For instance it would really help if the poles have one input and 3 outputs, for instance.

That way a pole can only give power on it’s outputs if it has power itself.

If you just try and connect them in a web it will be like a kind of ‘travelling salesman’ nightmare…

I have a “kinda” working method but it doesn’t really do what it needs to do:

Project video

Basically if you see the last two Nodes (green and red) the green energy is flowing too slow since it’s just 1 “ten-generator” against many green generators.

The energy spreads evenly between Nodes (generators, conductors, poles etc.), but the last bit the energy should flow only in the “red direction”.
This is caused by a “never-ending” gain/lose energy situation.
The only thing that makes this not a loop is just because the Conductors/Nodes sends their excessive energy to the next not-full Conductor/Node.

It’s kinda complicated to explain in words.

Anyway that’s why I wanted to try the “connected” solution but as you said it seems like it’s complicated as well but I actually didn’t try to do what you said as I think it will take a huge impact on performances but at this point I think I could try and see how it goes.

If you have a solution to my other “kinda-working” method (if you understood how it works) please let me know.

In the meanwhile thank you very much for the help.

I also want to thank @ClockworkOcean for his last suggestion.
If everything goes wrong I might take into consideration your I/O solution.

This is a pretty Interesting question. It might help to read a little about data structures, specifically binary trees and linked lists. It won’t be an exact answer since the number of inputs and outputs that you want may vary. Think about a node (or pole) as a single entity first. The node has to identify whether it is attached to a parent, and whether it has child nodes down stream.

Each node A) keeps a reference to the child beneath it, B) has the same state as its parent node and C) is marked as a root node (generator) or not.

When a node is detached from its parent, if it is not a generator, you trigger an event or function that traverses through the lower nodes and updates the pole states.

Sorry if that’s a bit too technical. I’m interested to see where you go with this. I might try it out later if I have time and update.