In today’s screenshot, you can see (some of) the individual building blocks of the MMORPG Tycoon 2 terrain. I don’t know whether they will be visible in the final version of the game, but I thought you might like to see them now.
In essence, the MMORPG Tycoon 2 map is constructed from the cells of a Voronoi Diagram, with each game “region” composed of a single Voronoi cell. Each of these regions is itself filled with more Voronoi cells, and these central cells become very important to the underlying structure of the game.
For me, the “maybe somebody else has already solved this problem” probably should have been two years ago, when I first set up this system. I wrote all of this geometry code myself, and while most of it worked really well, there was one bit of which which didn’t; clipping the embedded Voronoi cells inside each region, to maintain the region boundaries. I struggled with that code for many days, trying to make it work reliably.
Don’t get me wrong; the code mostly worked. It worked about 99.9% of the time. There were only a few really awkward situations which would cause it to fail. But as you can see from the screenshot, there are actually a lot of Voronoi cells in a map — even a small one, like this. My code would tend to fail about one time per five maps. I’ve spent many, many days trying to make the system work consistently, over the years.
Then today, after spending almost another full day debugging the problem, I finally thought, “I bet someone else has already solved this problem”. Fifteen minutes later, the problem is solved, simply by adding some source from The Clipper Library. It’s much more powerful than what I actually need, but it handles my simple clipping problem without breaking a sweat. Big kudos to its author!
So for future reference: When stumped, particularly on something geometry or physics-based, go looking for a library. They can save a huge amount of your time, and get you back to working on the things that you’re actually good at working on.