Progress Report, July 2012

Posted by

Two months since the last progress report, but a lot has happened. I had test devices stolen, posted a semi-popular post on garbage collection in Android, and had a lot of fun writing my series on planet rendering.

Star and Planet Rendering

I've now got star and planet rendering integrated into the game. Every star and every planet is totally unique and generated on-the-fly as you browse the world. Here's a few shots showing that in action:

Starfield view, notice the neutrino star in the top-right

Solar system view, with an orange star

Solar system view, with a yellow star

I'm still having issues with the speed of rendering, though. It all happens in a background thread, so it's not like it affects the actual gameplay, but it can take several seconds for the actual final rendered image to pop up when you visit a new area. I'm not sure what the best way to handle that is, maybe a place-holder image is good enough?

Ship Fleets

I've also started work on handling ship fleets. You build ships in shipping yards, which you can build on a colony. Once you colonize a planet, you can click on the "Build" button, go to the "Ships" tab and choose which ship to build.

You can have as many ships in progress as you like, but the more in-progress ships you have, the slower progress is (you basically need to divide your population between all ships -- workers here haven't read The Mythical Man Month: the more workers you can have build ships, the faster the ship gets built, directly in proportion to the number of workers.

Once you build some ships, they show up in the "Fleet" screen, which you can get to by tapping the "Fleet" button in the solar system view. Tapping that brings up this screen:

The fleet screen, with two kinds of ships showing

You can see here, I've got 7 scouts and 2 Colony Ships. On this window, the only function I've actually implemented so far is the "split" function. This will be useful if you want to send some of your ships to one place, and some of them to another place: split them up and send them on their way. Select a fleet, then tap "Split" to bring up the "Split" dialog":

Splitting a fleet

You can either drag the slider from the left to right to adjust the split, or you can type a number directly into the box. Click "Split" and the fleet is split into two:

The scouts have been split into a fleet of 5 and a fleet of 2

Coming Up

Coming up, I'll be working more on the fleet design. Once you can start moving ships from starsystem to starsystem, I think we'll really start having the beginnings of a real game!

Generating Names

Posted by

I mentioned a while back that I wasn't all that happy with my random name generator. So I've been working on it a little, trying to tweak the algorithm to generate names that are "good". I define "good" as:

  • Easily pronounceable – unpronounceable names are hard to remember, you need to know where you have your big armada of ships, and you're not going to be able to do that if you can't even say the name of the star.
  • Interesting – this goes without saying, really
  • Allow for a large corpus – it's no good if every second star is called "Sol" or whatever

The algorithm I had been using before was one that I'd just taken from somewhere on the internet. It wasn't that great, because the input files were really hard to generate and maintain. The old generator would take files that looked like this:

-a
-au +c
-bi
-br +v
bu
nul +v
au +c -c
+tor

(Obviously, this is just a sample of the file.) Basically, lines that start with "-" represent the beginning of words. Lines that start with "+" represent the end of words. A "+c" means "can be followed only by a consonant", "-c" means "can only be preceeded by a consonant" (similarly, "v" for "vowel").

Now, this is actually quite powerful. To generate a name, you just randomly choose a start syllable, then start filling in the syllables from the rest of the file, based on whether they start with a consonant or vowel, etc. There are three main problems with this:

  1. Coming up with the rules and tweaking them is really hard
  2. There's no real way, other than duplicating rules, of saying "this particular combination is really common" or "this particular combination is really rare", and
  3. Coming up with the rules and tweaking them is really, really hard

So I decided to scrap that and think of something myself.

A simpler solution

I figured an easier algorithm would just be to take a whole big corpus of existing names, and mix them up. If the size of the corpus is big enough, we should be able to generate names that follow the same basic rules of the corpus, without having to manually tweak them. And we'd get the frequency of combinations about right, too.

The code to load up a corpus file is below:

def _parseCorpus(file_name):
  """This class parses a corpus file.

  The corpus file is really just a list of words in a
  certain "vocabulary" (e.g. Viking names, English names,
  etc). We parse the words from that file, and for each
  pair of adjacent letters we determine which letters are
  most comment next to each other.

  Returns:
    A mapping of letter-pairs to a list of "subsequent"
    letters and the number of times we saw that letter
    after the letter pair.
  """
  letter_frequencies = {}

  def addLetter(last_letters, letter):
    if last_letters not in letter_frequencies:
      frequency = {}
      letter_frequencies[last_letters] = frequency
    else:
      frequency = letter_frequencies[last_letters]
    if letter not in frequency:
      frequency[letter] = 1
    else:
      frequency[letter] += 1

  with open(file_name, 'r') as inf:
    for line in inf:
      for word in line.split():
        last_letters = '  '
        for letter in word:
          addLetter(last_letters, letter)
          last_letters = last_letters[-1]+letter
        addLetter(word[-2:], ' ')

  return letter_frequencies

This code will take a file which contains a bunch of words, and then generate a "corpus". The corpus consists of a mapping of letter pairs to a list of subsequent letters and the number of times we saw that subsequent letter in the corpus.

For example, if you have the word "Dûrion" from my "Elvish" corpus, the letter pairs and subsequent letters are:

'  ' -> 'D'
' D' -> 'û'
'Dû' -> 'r'
'ûr' -> 'i'
'ri' -> 'o'
'io' -> 'n'
'on' -> ' '

We start by mapping "  " (two spaces) to the first letter in a word. Then " D" (a space followed by a letter) to the second letter in the word. Continuing on so that "ri" is followed by an "o" and so on.

Actually using this to generate words can be done as follows:

import random

def _generateName(corpus):
  """Generates a single name from the given vocabulary data."""
  def getLetter(last_letters):
    if last_letters not in corpus:
      raise ValueError(last_letters)
    frequencies = corpus[last_letters]
    max_frequency = 0
    for _,count in frequencies.iteritems():
      max_frequency += count
    index = random.randint(0, max_frequency)
    for letter,count in frequencies.iteritems():
      index -= count
      if index <= 0:
        return letter
    return ' '

  word = ' '+getLetter('  ')
  while word[-1] != ' ' and len(word) < 10:
    word += getLetter(word[-2:])
  return word.strip()

We pass a pair of letters, representing the last two letters generated, to getLetter, which looks up the corpus for that letter pair, which will give us the list of subsequent letters and their frequencies. We then generate a random number and choose the next letter from that list.

To get the ball rolling, we need to pass in "  " (two spaces). We also stop when getLetter returns a space (which represents an "end-of-word" in our corpus).

I found I had to put a maximum word length, otherwise you end up with mega-names like "Thamorthamollassëa" which, while still kind of pronounceable, is way too long to be memorable.

Corpus

I had a look around the internet for lists of names that I could use as my corpus. I found a list of "Nordic" names, which lets me generate names like:

Hun Jonarraf Jora Keti Egi Sigrir Erid Hjora Bikki
Fenjar Thorhall Atlif Skulif Tjorstric Sverda

A list of "Elvish" names let me generate names like this:

Verlassë Adan Maithredhi Mair Manwë Caldon Tawartion Thaldorcon
Aindion Morcionwë Alya Maidhion Ainion Glassien Urúvion

And so on. I think these names are generally much better than what I had before.

So now, when generating star names, I choose a random corpus (Elvish, or Nordic, or Latin, etc), then a random name from that corpus. That gives a nice mix of naming styles for the stars, and hopefully makes the world a little more usable.

Customizing your star names

While better than before, I don't think it's really possible for a randomly-generated name to have quite the same impact as a human-generated one. I'm considering allowing players to rename the stars they colonize to be whatever they like. I think that would give players a much greater sense of "ownership" if they choose the names of their stars.

Maybe there just needs to be some simple rules. Like you can't rename a star more than once per x days, you can't rename a star until you've had a colony there for y days without any other players colonizing, etc. I'd also like to be able to stop horrible names like "-}[GJH]{- Poo" or something that'll just throw you right out of the immersion.

Designing the "Empire Overview" screen

Posted by

As I play around with the game, one of the things I find difficult is know where all of your Empire's colonies are. You can browser around the starfield map until you find the "colony" icon, tap the star and it'll tell if you one of the colonized planets belongs to you. In the future, I also plan to colour-code those icons so that you don't actually have to tap it to find out if it's yours.

But that's still rather annoying. It would be much better to have a centralized screen where you can see all of your Empire's colonies, ships and so on at a glance.

Initial design

Below you can see my initial design "mocks" for this new screen. I am calling it the "Empire" screen, and you can access it from the "Empire" button on the main starfield view. So far, I envision three main "tabs" on that screen. The first one:

The Empire Overview screen

It shows an "overview" of your Empire: number of planets colonies, battles won, etc. I'm not entirely sure how I'll do the tabs, using the build-in Android tab control is a bit of a pain because it takes up so much space and is kind of hard to theme. Anyway, for now I've just got buttons at the top. The second screen:

The Colonies screen, show all your colonies on all planets

It shows a list of all your colonies on all planets. This way, you can quickly navigate between your colonies, and see what everybody is doing at a glance. The third screen is the fleet screen:

Fleet screen, showing all of your fleets

If this looks similar to the screenshots I posted last month, well that's no accident. I'm planning on having this be almost exactly the same as that screen, the only difference being that it'll show all fleets across all stars in your Empire, not just the fleets in that particular star.

In-Game

Now that I'm reasonably happy with the above mocks, I've integrated an initial version of the screens into the game. Currently, they're not showing a whole lot of useful data, but that can be tweaked as I play more and learn what kinds of things are important.

So first, here's the main "overview" tab:

In-game screenshot of the Overview tab

There's not a whole lot of info here for now. I think we could add general statistics like "Number of battles fought", "Number of battles won", "Ships lost", "Ships destroyed", etc. The top-left of the window has your empire name and (in the future) you're empire's logo. I'm thinking one way of monetizing the game would be to allow you to buy in-game items and customizing your empire's logo would be one way of doing that (otherwise, you have to choose from a limited set of icons, say). Anyway, tap on "Colonies" and you get this tab:

In-game screenshot of the Colonies tab

Down the left-hand side you can see all of your colonies. The icon in the list shows you the star behind the planet. The name of the colony is the name of the planet (which is the name of the star followed by the roman numeral number of the planet). Selecting a colony shows some statistics on the right. Currently it's not very useful, but showing things like what the colony is currently building seems like it would be useful. You can tap on "View" and it takes you directly to the Solar System view with that colony selected. Otherwise, tap on "Fleet" to bring up the Fleet tab:

In-game screenshot of the Fleet tab

Here you can see all of the fleets you have. The list on the left is broken up by the stars to which the fleets belong. As we saw before, this screen is actually the same screen you see when you tap on the "Fleet" button in the Solar System view. It's really just a shotcut where you can access all your fleets at once.

So that's it for the "Empire Overview" screen. At least for now - in the future we'll need to include plenty more information and detail on these screens. But even now I'm already finding the ability to quickly flit from colony to colony quite handy.

Slight setback

Posted by

So I had a slight setback in War Worlds development last week... my house was broken into and all my test devices were stolen! Luckily, they didn't take my main development PC (even though all my code and such is backed up to the cloud, it would still be a much bigger pain if I had to rebuild my whole development PC!)

They took (amoung other things), my old Samsung Galaxy S (which was my "low end" device), a Nexus S and my Motorola Xoom (which I was using to make sure the game ran OK on a tablet).

I still have my day-to-day Galaxy Nexus, but that's a pretty high-end device and I normally use the low-end devices for regular testing to make sure I don't do anything stupid performance-wise.

Anyway, for now I'll stick with using the emulator and maybe someone at work will have an old phone they're willing to part with. The show must go on!

Ship Fleets

Posted by

I've been thinking about how ship fleets will work in the game. This is a pretty integral part of the gameplay, so it's important that I get it right. Here's what I've go so far.

Solar System window

At the top, under the star name you can see there's a new "Fleet" button. Ship fleets are a solar-system "global" thing, so if you build ships on two planets they all contribute to the "solar system"-wide fleet. I'm not sure if this is the best location for this button (there's space for another one there as well, but I'm not sure what would make sense...)

So clicking on the "Fleet" button will bring up something like this:

Fleet mock

I am thinking that the way this will work is, on the left you can see a list of the fleets you have. Each fleet is always a single "kind" of ship (scout, fighter, bomber, etc) and the number of ships in that fleet are shown in the list. Tap on a fleet and you get various options on the right:

  • Stance describes how the fleet reacts to enemy fleets appearing in the solar system. Do they attack immediately (aggressive), do the only attack if attacked first (defensive) do they avoid contact altogether (passive), etc.
  • Move and Attack buttons will allow you to direct a fleet to move to a different solar system, or begin attacking a solar system.
  • Split and Merge buttons will allow you to split up a fleet into two, or merge two fleets (of the same ship design) into one fleet.

The main thing I'm having trouble with at the moment is the "Move" and "Attack" commands. Once you've clicked the button, then what? Do we show you a list of nearby stars? Do we pop up the starfield view where you can scroll around and choose the star to move to? This will require a bit more thought methinks.