Saturday, June 1, 2019

RTS_19 "Capitals & Random Name Generating"

I was actually pretty excited about this update. It involved a lot of math & pure-programming which is some of my favorite kind of programming so it was quite fun to work on.

In order to make it feel more final and part of the game I added 2 more test players to the game (Totalling 4), which I think is the perfect amount for this test map size (64x64):





Each player has a distinct color so that they're easy to tell apart. I've also introduced random name generating for creating new cities. Eventually, you'll be able to name cities yourself, but they'll always start off with a pre-determined name.

These sorts of updates (Ones that involve a lot of math & a challenge) are my favorite kind. Now, let me break down how spawns are determined:

First, a set of points are generated across the map using Poisson Disc Sampling. This means that not every hex on the map will be checked.

On a 64x64 map, there are 4,096 hexes. Having to then go through and check all 4,096 of them to see if they're a valid spawn point or not would take an insane amount of time. So using my method of Poisson Disc Sampling only 652 hexes are checked.

So here is the original map:



And here are all the points that are generated:


As you can see, it's a lot fewer than having to check every single tile! The pattern it creates is also intentional, I didn't want it to be a straight grid since I wanted every tile to have a chance of getting added to the list instead of just every other which would then guarantee that certain tiles had a 100% chance of never getting checked, which I didn't want.

After that each point goes down a checklist, each time getting more and more specific. This was done so that the harder calculations were done last, that way if it checked off an easy one it would never have to check the hard ones. This also helped reduce calculation time significantly.

So now, what makes a valid spawn point?

A) If the spot is in shallow or deep water, it is removed from the list.
B) If the spot is on a river, then it is removed from the list.
C) If there is a mountain with 2 tiles, then it is removed from the list.
D) If the tile has no shallow water tiles near it within 1 tile, it's removed from the list.
E) If all the shallow water tiles near it have ridges, it's removed from the list.

After having met all of those criteria, we finally have our list of valid spawn locations:
(Note that all of the points on these maps were colored manually so I may have missed some)

Here's that same map but with arrows so that the valid spawn points are easier to identify:


With this map, there are now 33 valid spawn locations.

Now that we've determined which spawn locations are valid, each player is assigned a spot from the list randomly. If the spot they've been assigned is within 16 tiles of another player's spot then they do it again until they find one that's far enough away.

With all of that out of the way, what have we accomplished? Well, the player will:
  1. Never spawn in the water lol
  2. Always spawn a distance away from mountains as to avoid getting trapped.
  3. Always spawn on the coast so that they have a good spot for a harbor.
  4. Always have at least one shore tile clear of ridges so that they have a spot to build.
  5. Always spawn a good distance away from other players so that they have to chance to expand before running into anyone else.
On this particular map, all 4 players had a valid spawn location within half a second, so I'm very happy with how it turned out. Another reason it turned out so well is I have it all running on a separate thread which will ensure that your game doesn't freeze during this calculation & that it'll take less time to do overall.

You may be wondering why I spawn a capital city instead of a settler, and that's because I think that starting off with a settler takes away from the game, I'd rather that players be able to get into gameplay right away by already having a city.

That's all for this update, I'm really happy with how it turned out and it was pretty important to do sooner or later so I'm glad it's all taken care of.

Sincerely,
Blake Gillman

P.S
As part of my push to move things out of the editor, I moved the button to generate the map onto the player's UI. This button is completely temporary, but it'll let me generate the map while playing the game which is more convenient.


No comments:

Post a Comment