Sunday, March 05, 2006

Friends of cat milk

I've been re-architecturing the code. I'm in stage 3 of my game at the moment. Each stage is a quite vague but large chunk of the game. Chunk 1 was pretty much Game Programming For Monkeys, Chunk 2 was a GUI system and getting display bits perfect.

The goal for this particular chunk is cities and talking NPCs. The NPCs will talk but you won't be able to join in the conversation. According to my todo list this goal is really close, luckily I know better it's actually miles away!

Recently I finished the city placement alogrithm - it's good but has a few flaws. Here's some psuedo code:


Before I even start, my mapdata goes through a preprocessing stage
where all landmasses are picked out from the sea. Then the
landmassesare sorted into continents, islands and desert islands
- according to some fuzzy-rules.

Once that's all done I'm ready to place my cities.

First I try to place a city on each continent.
If I run out of cities then I return success.
If I run out of continents then onto the next phase.

I make a copy of all the continents.
Each copy is list of points where a city can be placed on a
continent. I go through the cities I've already placed and
remove these positions from the copied-continents, I also
remove the all tiles in a 9 square radius.

From these copies I then randomly pick positions.
I place the city at the picked position and then remove its
postion and a 9 square radius footprint from the continent copy.
If all cities become placed I return a success.
Otherwise when all the position continent copies are empty
then I reduce the number of citys to match what I've place and
I return success.

Notes: I don't even try to place on islands and some of those
can be quite big. Otherwise it's not a bad algorimth.


My current implementation does actually pick islands as well but only one city per island and it favours islands towards the north of globe. Anyway the results are nice.

I need to patch that generation algorithm into my main code but before that I'm poking around. In my game menu when I'm selecting what game to play - I want to be able to see a preview of the world. Therefore I need to be able to get the data much higher up in my code. So shuffling a'plenty.

Also it's getting nearer and nearer the absolute end of putting off some new tile art. So I'm going to have to have a go at the soon.

There's an interesting thread about Random City generation over on rec.games.roguelike.development
group.

Also from the C# Faq, a question I was recently pondering.

How are return values from a delegate handled?

Q: How are multiple return values from a delegate handled?

In C#, it's possible to write a delegate such as:

delegate double GetResult(params double p);

If there is more than one method on this delegate, there are multiple return values.

A: In this situation, the return value is the value that is returned from the last delegate.

If you want more control on this, you can call GetInvocationList() on the delegate, which will allow you to call each method individually, and process the double values appropriately.
Post a Comment