How do I Connect random generated nodes together??

Get help using Construct 2

Post » Mon May 16, 2016 10:03 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon May 16, 2016 10:33 pm

@Pulstar, that's cool! Nice work!

@99Instances2Go, yeah, that looks a lot easier! When I enter 10 for the variable How_Many_NODes I never get 10, I get a random amount under 10, am I missing something?


A second question, how do I make this static once it's generated?
For example, in a run of the game I would need to generate 10 of these on the start of the game and I would need access to these during the game.
B
16
S
9
G
12
Posts: 40
Reputation: 7,518

Post » Tue May 17, 2016 6:03 am

evillair wrote:A second question, how do I make this static once it's generated?
For example, in a run of the game I would need to generate 10 of these on the start of the game and I would need access to these during the game.


They already are static, so long as you do not run the generation events again or change layouts in game. Any loss of nodes on layout changes can be avoided by adding persistent behaviour to all randomly generated objects. You just need to remember that when you switch back to a layout all initial objects (stuff you place/see in the editor) will also be placed. So you need to check carefully if everything is where it should be and no new objects appear. Or worse, so you don't delete already existing nodes when deleting initial objects.

Alternatively, since you just need it for a map where you just pick it once every 5-15 minutes and do nothing else, you can have the sector branching map a separate layer above the fully random node map. Hide that layer when it is unneeded (FTL does this with the star map I think). However that approach has a different problem. You need to add some conditions to all clickable objects/nodes so that nothing happens when the branching map is visible or invisible. On clicked/touched events for invisible sprites to register.

Personally, as my current project is using lots and lots of window/screen for procedurally generated spaceships. I add a boolean to all button objects, if say ship weapons or ship cargo screens are visible (ship window button is set to true) I do not allow selecting a different ship to work as the ships are on a layer behind the window screens so you could click-through them.

If you go with the layer approach, I also recommend naming your layers and always using the string/text name in events (not the layer number), as adding deleting any layers of your project changes the layer number order and it becomes a chore changing all the numbers to the current ones and keeping track of them.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Tue May 17, 2016 2:26 pm

Thanks Pulstar for some good ideas!
Yeah, I learned quick to use naming strings for layer selecting :)

Thanks again, it's appreciated.
B
16
S
9
G
12
Posts: 40
Reputation: 7,518

Post » Tue May 17, 2016 10:21 pm

I solved the disconnected isles issues. Red lanes are lanes created by the gap-bridging logic I created:

Image

Basically I added another boolean to nodes, which is only set to true after the connect function is fired for nodes connected via lanes to the initiating node. So if the number of nodes that are checked and the number of nodes that are connected is the same, but it is not equal to the number of total nodes, it means that unconnected nodes exist. Then I launch a "Pontifex" function that finds connected-unconnected node-pairs that have the least distance between their nodes. It retrieves two such pairs, creates lanes between them and lanes between the second least distant unconnected node, relative to the connected node of the pair. So 4 lanes per gap with two choke-points per gap. The overlap function may delete a lane or two, but it is guaranteed to create at least one lane per every gap (two for most).

It then goes back before the connection checking functions and runs them again. Once it finds that checked nodes=connected nodes=total nodes it stop running the generation logic.

https://www.dropbox.com/s/d1qsk715wkmtz ... .capx?dl=1
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Wed May 18, 2016 2:06 am

Hi @Pulstar, I'm still getting islands with your latest one...

Image

Perhaps because I'm using too low number of nodes? I only need 10-15 max.
Perhaps I broke something ;)

Image
B
16
S
9
G
12
Posts: 40
Reputation: 7,518

Post » Wed May 18, 2016 6:53 am

The solution should work for any number of nodes. Although the execution time should be proportional to the square of the number of nodes.

I think what is happening is the pontifex function not firing. Either because node booleans were not reset to false after new lanes were generated or because the conditions for it firing did not work. I did a few dozen runs of this and did not encouter the issue eith the version i attached to my previous post. Unless that is an old file.

Send me the link to your capx via PM. I wil check what the issue is in 10 hours when I get home.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Wed May 18, 2016 7:29 am

Done, thanks again.
B
16
S
9
G
12
Posts: 40
Reputation: 7,518

Post » Sun Sep 17, 2017 7:20 pm

Hello guys,

Sorry to bump this topic since all this time ^^' ... I prefer reopenit instead of open a new one ...

So this is why i'm here, i would like to make the Generation in a different way and i have start something that work well, but i'm stuck in this point, when i generate the link i would like a way for the algo do not create a link on a one that already exists or on a node near him, just can create link where no one exists and beetween random 0 to 3.

This is the begining of the CapX : https://www.dropbox.com/s/uqar7eh32i4px ... .capx?dl=0

Hope someone can help =D
B
19
S
8
G
3
Posts: 70
Reputation: 2,572

Post » Mon Sep 18, 2017 7:44 am

Hey @evillair, :)

Just an interesting note...
It might be worth looking at the "Delaunay Triangulation".
It's probably overkill for what you're building, and it specifically produces a mesh of triangles which is a bit stricter than what you require, but it has some nice properties.

The Delaunay Triangulation does a good job of connecting nearby points without creating sliver triangles.

It's the dual graph of the voronoi graph.
If you're familiar with voronoi patterns, for the Delaunay Triangulation, you get the center points of the voronoi cells, and create links between points in bordering cells.

Boris Delaunay, who came up with this Triangulation solution, worked on this back in the 30s. He also climbed mountains, and somewhere there's one named after him. I don't know much else about him, so I can only assume he lived as hard as he mathed.

Here's a visual animation of a Delaunay Triangulation algorithm working on a set of random points.
https://www.youtube.com/watch?v=FUkmgjB3tSg
B
27
S
18
G
8
Posts: 327
Reputation: 6,156

Previous

Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, gamecorpstudio, tarek2 and 18 guests