Updated: Aug 22, 2019

One of the things I'm most proud of in ACF is my map generation algorithm. At its most basic, each planet map is a square tile grid, with each tile marked as either a corner, an edge, or a center tile. (Center tiles can be further broken down into player barns, generic pens, "normal" tiles, and "special" tiles, like...well, you'll just have to wait and see about those.) For each planet, there's a list of acceptable tiles fitting each category, and when I'm generating the map at runtime, I iterate over the grid and randomly pick from the corresponding list to fill each space.

Got it? Good, because that's the really simplified version. There's a lot of math involved, for instance, when doing the actual placement. Knowing the map size parameter that the players chose for their session, in combination with the side length of each tile, can get us to the exact coordinates to spawn each tile. There's also a lot of balancing that needs to go on. Every map needs to have the four player barns, and after the Pre-Alpha placed them completely randomly, it became obvious that I needed some way to "spread them out", so that they wouldn't spawn directly adjacent to each other. I came up with a slightly-better grid implementation at that point, one which would let me place specific tiles in specific places. Now I can make sure that one barn is confined to each map quadrant, or place a special landmark at the exact center, if I want.

Methods like PlaceCornerTile(), PlaceEdgeTile(), and PlaceBarnTile() are all overridden in each of the subclasses, PurplePlanetMap and the others that aren't in the game yet. This is so that each can take care of any special considerations for that map. For instance, the crystal border along the Purple Planet's edge didn't match up quite perfectly originally, so I created a special, modified edge tile to place right before each corner. This won't be necessary for the upcoming city map.

And speaking of, I decided that I didn't want cows wandering freely down the city streets, which is a good segue into the last piece of the puzzle: how to distribute the cows. I sat down and created a giant spreadsheet that lists out the four maps in the three sizes crossed with the seven-ish game modes in their three lengths. By laying out the total number of center tiles available (once you subtract the player barns and anything else "special"), it was a little easier to determine exactly how many generic pens to place in each situation, how many cows should go in each generic pen, and how many should start freely wandering on each tile. Some parts of the spreadsheet were very easy to fill in: Hunt mode, no matter the size or planet, will only ever have one cow total, and CTC will always be four. The city map, as I mentioned, will have zero wandering cows, so all of them need to come from generic pens...and that's true whether you're playing a five-cow Time Trial or a large map Frenzy. All of those method overrides are necessary to determine exactly how to spawn cows in each map planet, size, game mode, and length combination.

The end result should turn out something like this: