How to get the neighboring regions of a region?

So basically i’m trying to make a grand strategy game (something like hoi4 or other paradox games). At this point i have selecting regions and displaying their information. This works by having 2 separate textures the colored map and the plain white map. I have colored each region in the colored map with different colors so in unity i can assign the colors to a province class which has a string for the name, an int for the population and also the color. To see what region i have selected i take my mouse position and convert it to a position to the texture get the color and try to match that color with any of my regions. Everything works great but i cant think how to implement which regions are neighbors but i dont want to take each region and assign its neighbors since i now have 139 regions. Thanks in advance!!

It sounds like you’re starting from the presentation part of the game without doing the underlying logic.

You might be able to write some clever way to analyze your presentation graphics and decide what touches what, what regions can connect to each other, but how would you even test that algorithm to make sure it worked and didn’t inadvertently leave two regions disconnected, or connect regions that shouldn’t be connected?

I would recommend taking a moment to do it properly and connect up your regions as you see fit. Personally I’m a big fan of connection lists, some kind of data structure that specifies what regions connect to what in a big list. That lets you easily edit and verify them, and then if you change your presentation in the future, the connection list still stays valid.

1 Like