Pond digging
November 2023
One of the bigger improvements of koi farm 2 is the fact that the ponds and surroundings can be customized by the player. This isn't just important because fixed ponds will eventually always be too small for all your koi, it's also a nice progression mechanic. It allows the player to fully customize the entire scene, not just the animals.
I decided to not add variable depth to ponds. It would be tricky to edit, and deep ponds are annoying because they make it hard to see all your koi or grab them out of the water. Instead, all ponds will have the same (rather shallow) depth, while still being deep enough to allow koi to swim at various depths. Since all ponds have the same depth, defining ponds is simple: they can just be polygons, and I'll model a slope down to the fixed depth from there.
My first (misguided) intuition was to edit the polygons by pushing the vertices away from the mouse, and resolving any (self)intersections after moving it. This led to a very complex algorithm which would try to resolve these intersections logically.


Unfortunately, I kept discovering more and more edge cases which couldn't always be resolved by my algorithm. If the user for example moved the mouse very quickly while digging, dozens of polygon intersections would need to be resolved, and there wasn't a single right way to do it. I had to discard this method completely.
Instead, I implemented the marching squares algorithm. Instead of deforming polygons, the player now digs into a "ground grid", which contains the depth for each grid point. The marching squares algorithm then gives me polygons enclosing all dug out areas. The image below shows these polygons before and after smoothing.

One major advantage of marching squares over my old polygon solver is that I can handle nested polygons much more easily. A polygon inside a polygon should be an island, but a polygon inside a polygon inside a polygon should be a pond inside an island. My old polygon solver had great trouble dealing with this, but the new algorithm allows for any nesting level, which removes constraints for the player and allows for much more creative pond designs.