|
Post by Darren on Jun 5, 2016 16:27:59 GMT
Hi, I'm stuck with rivers and what methods are available to check whether there is a river from one node to another.
I have tried to loop RiverDefinition.definitions after generating a map with rivers but it is returning nothing ( empty list ).
What do I need to access to get a list of rivers and their position on the map, or between which hexes the river is passing?, thanks in advance
|
|
|
Post by Darren on Jun 6, 2016 22:17:26 GMT
Maybe someone can share a method or something similar (even pseudo-code) that takes IsRiverBetweeen(Hex a, Hex b)? Thanks
|
|
|
Post by khash on Jun 14, 2016 19:46:34 GMT
ook, I had tea break so why not: public void FindRiverCrossings() { //for each river in the world foreach (RiverData rd in riversStart) { RiverData thisNode = rd; RiverData nextNode = rd.next; while (nextNode != null) { //each two river nodes HAVE TO HAVE 2 common neighbours. List<Vector3i> pair = new List<Vector3i>(); foreach(Vector3i neighbour in rd.neighbours) { if (nextNode.neighbours.Contains(neighbour) ) { pair.Add(neighbour); } if (pair.Count == 2) break; } Hex a = GetHexAt(pair[0]); Hex b = GetHexAt(pair[1]); if (a.viaRiverHashSet == null) { a.viaRiverHashSet = new HashSet<Hex>(); } if (a.viaRiverHashSet.Contains(b)) { a.viaRiverHashSet.Add(b); } if (b.viaRiverHashSet == null) { b.viaRiverHashSet = new HashSet<Hex>(); } if (b.viaRiverHashSet.Contains(a)) { b.viaRiverHashSet.Add(a); } } } } you may need to add public variable to Hex class: public HashSet<Hex> viaRiverHashSet; and this function to World class Note its written in notepad, so its untested, but shoudl be better than pseudo code
|
|
|
Post by Darren on Jun 15, 2016 1:12:12 GMT
I am sorry for troubling you into making this for me and I appreciate your answer (thought I wouldn't get one tbh haha).
I really really appreciate it, and learned from this, thanks a lot, didn't realize it was river data not river definition, oops.
Thanks again, Darren.
|
|
|
Post by khash on Jun 15, 2016 8:53:38 GMT
ah I just realized this code is missing advancing on river nodes. thisNode = nextNode; nextNode = nextNode.next; and logic is wrong, eg: if (a.viaRiverHashSet.Contains(b)) should be if (!a.viaRiverHashSet.Contains(b)) see this is why coding is much easier when you do that in the editor or at least reading what you write
|
|
|
Post by Darren on Jun 16, 2016 23:59:56 GMT
Hey the problem now is that when you do .next, the RiverData returned has 0 neighbors, thus it will never find any pairs when comparing and the hashsets remain empty.
I tried calling GetNeighbors after i do .next but this returns only 1 neighbor and since you need 2 neighbors minimum for it to work, it's not working.
Thanks for the help bdw.
|
|
|
Post by khash on Jun 17, 2016 17:00:55 GMT
hmm I'm not really sure why it would not work, are you sure you are not calling it on the interpolated river data?
|
|
|
Post by Darren on Jun 18, 2016 6:54:17 GMT
I found out river data is being saved/ generated with nodes that are not in the .5 range, like for example 7.43452 etc .... so when it goes into GetNeighbors, the offsets wont return true and they won;t be added to to the neighbors list. Is it my version only that's making river data with values that are not into .5
|
|
|
Post by darren on Jun 18, 2016 7:20:22 GMT
This is a screenshot of a river I generated with it's next nodes. Also the import is fresh (I re-imported it to check if it was something I have changed). There is a method call in GetNeighbors called IsNextToThisPoint(pos) and this method returns true if the offset between pos and the hex position is 0.5. This can never be true for river nodes that are not with a decimal .5 Hope I explained myself better. I'm going to try rounding all river nodes to .5 , maybe it works. Thanks again for your time. EDIT 1: I have debugged all the river generation in CreateRivers code and the river nodes were generated as expected with .5 decimals. I'm guessing that somewhere else the position is being altered and it's losing it's .5 decimal to something like .4293
|
|
|
Post by khash on Jun 18, 2016 8:13:06 GMT
world space coordinates are different than hexagonal coordinates. Also ensure you are not tracing interpolated values as those you show here seens fairly dense
|
|
|
Post by darren on Jun 18, 2016 8:39:37 GMT
I don't understand what you mean by interpolated values. The nodes shown there are of 1 river that starts from 2.5, -4.5, 1.5 and ends at -0.25, 3.25, 3.5 ( which when generated it's actually fine but than gets messed up values after generation). I am using the method that you gave me for finding river crossings, so I should be using the correct variables. The problem is occuring here:
|
|
|
Post by khash on Jun 18, 2016 9:11:48 GMT
Rivers call PostProcessRiver which interpolates base river nodes. You may want to mark (eg add specal boolean) to nodes which are build before interpolation. And then use this ti identify them to find hex neighbours.
|
|
|
Post by darren on Jun 18, 2016 9:56:59 GMT
O my god I am so dumb, there was already a method that did this in the original one, all I hadto do is use the list variable in the hexes called directionsPassingRiver which is exactly what I was trying to implement but works perfectly since the list is generated before the post process. Sorry for wasting so much of your time but I really appreciate the help and have learned a lot. Thanks for the wonderful package I'll go write a nice review on the asset store page for you Bdw nice game you have there on steam, congrats.
|
|
|
Post by khash on Jun 18, 2016 10:03:49 GMT
Hmm I wasnt lookign there for too long time I think So I forget we had this functionality already Good luck, and thanks!
|
|