Each one of my celestial bodies is based on a class which extends from a class, which in turn extends from more classes. In fact, if you want a look at the class tree at the moment for in-game objects, it's something like this:
So, as we can see, that's a lot of inheritence. I know you can't read the names properly here because it's so small, but the bottom-right block is where the stars, black holes and planets are. They inherit from things like mineable, dynamic, moving, massive, etc abstract classes. All designed to very easily encapsulate their own little pieces of functionality which has made crafting this game a hell of a lot easier.
An important part of Pigment will be exploration. I want it to be more meaningful than just zipping about, seeing what we can see. To start with I want to reward the player for finding new areas and I want the player to have to actively compete with other characters to be labelled the discoverer of that object (and be given the honour of naming it, of course). As such these things had better be a little more unique than "brown star", "dwarf planet", "moon". I need them to feel like they're individual, beautiful entities, born from the swirling fires of the galactic core and battered by the chaos around them. I took a big leaf from Dwarf Fortress here, which is probably the best case of procedurally generating attributes and descriptions there has ever been.
So how do I do it? Well, from every class, even right at the top, there is an overidden function Describe() which returns a string. The string it returns constitutes the current state of the description. So right at the top it will return "This object is a blue, supermassive star." and towards the end you might be getting a bit more detail. Each implementation of the function returns the parent class' string result combined with their own descriptive contribution in order to call the Describe() function on every class that is relevant.
So what does the code look like? Well here's the implementation for the Discoverable abstract class:
public virtual string Describe()
{
if (Discovered)
{
return "It was discovered by " + Discoverer.Name + " in " + DiscoveryDate + base.Describe();
}
return "It has not yet been discovered." + base.Describe();
}
So here are a couple of descriptions that have been generated so far
This star has no name. It is unstable, with a temperature of 3574600C. It will likely collapse in 8000 million years. It can best be described as Yellow in colour. It is approximately 128 billion years old and it has a radius of 191AU. It has not yet been discovered.
This star has no name. It is unstable, with a temperature of 143400C. It will likely collapse in 1000 million years. It can best be described as Blue in colour. It is approximately 90 billion years old and it has a radius of 309AU. It has not yet been discovered.
This star has no name. It is unstable, with a temperature of 123130C. It will likely collapse in 1000 years. It can best be described as Dark Red in colour. It is approximately 100 billion years old and it has a radius of 252AU. It has not yet been discovered.
These are mostly randomized data in there, a lot of it just doesn't have the proper code to calculate things like size and colour so they're randomized, but later on this will give some highly scientific readings, and I hope to include orbit information and major events too.
In the future I hope to hook this description system up to some sort of text-to-speech engine and actually have the ship's computer read out data about it as you fly along. Space games always break with immersion as soon as you have to bring up a menu while you're flying along, because when that happens you're powerless to control your ship, so I want to have minimal reading and menu clicking where-ever possible.
For example, the class description for collapsing would have multiple possible wordings chosen based on the planet ID:
[i]It will likely collapse in 8000 million years.[/i]
[i]In 8000 million years it will probably collapse inward.[/i]
[left][font="helvetica, arial, verdana, tahoma, sans-serif"][color="#282828"][i]8000 million years from now, this star will collapse.[/i][/color][/font][/left]
[left][i]This star will probably collapse in 8000 million years.[/i][/left]
[left][i]It is estimated to be 8000 million years before this star collapses upon itself.[/i][/left]
[left][i]The probability of this star collapsing within 8000 million years is high.[/i][/left]
[left][i]Calculations chart this star's lifespan to be about 8000 million years before collapsing.[/i][/left]
[left]If you can come up with similar word variations for each one of your subclasses, it would add alot to listening to your ship's computer while flying.[/left]
[left]"[i]This is a nameless star. Being unstable, it has a temperature of 123130C. It is likely it will collapse in 1000 years. It is Dark Red in colour. This star has a radius of 252Australias and is over 100 billion years old. It has not been discovered yet.[/i]"[/left]
[left]If you could find a way of mixing the data into seamless sentences, that would be every more incredible and smooth-flowing.[/left]
[left]"[i]This nameless star has a temperature of 123130C, is Dark Red in colour and is likely to collapse in 1000 years. It is unstable, and has not been discovered yet, but has a radius of 252AU and is likely to collapse in 1000 years. It's age is estimated to be 100 billion years old.[/i]"[/left]
[left]Maybe you could get it flowing smoothly by having each class add "segments" of info to an array, which is randomized in appearance order at creation.[/left]
[left]It is then broken into randomly chosen sentence structures for the planet's description:[/left]
[left]Structure examples:[/left]
[left][i]"This [/i][i]<element> is[/i][i] <element> and <element>."[/i] (three element sentence structure).[/left]
[left][i]"It <element> and <element>, with <element>"[/i] (a different three element sentence structure)[/left]
[left][i]"<element> and <element>" [/i](a two element sentence structure)[/left]
[left](This star has eight elements given to it by various inherited classes)[/left]
[left]It might generate something like:[/left]
"This [b][color=#008080]nameless star [/color][/b]is [b][color=#daa520]of a Dark Red-ish hue[/color][/b] and [color=#008000][b]has a radius of 252AU[/b][/color]."
"It [color=#800080][b]will probably collapse in 1000 years[/b][/color] and [color=#a52a2a][b]has not yet been discovered[/b][/color], with [color=#4b0082][b]a temperature of 123130C[/b][/color]"
"It [color=#ff8c00][b]is unstable[/b][/color] and [color=#008000][b]is approximately 100 billion years old[/b][/color]"
I get excited by things like this. [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]