A Description Engine

posted in Nick's Corner
Published May 15, 2012
Advertisement
Ok, so it's not the octree-based gravitation I promised you, but I came up with a very last-minute massive overhaul idea for aesthetics which has slightly broken the octree code. No biggie, but it's gonna take a bit longer to fix. On the plus side I am very excited indeed for the new look of the thing, which I'll show you at a later date. So this time I'm going to talk to you about descriptions.

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:

classtree.png

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.
1 likes 4 comments

Comments

Servant of the Lord
Very nice! I think it would be cool to randomly select variations of phrases too, but constant for each planet, maybe from their planet ID or whatever.

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]
May 15, 2012 04:47 PM
NickUdell
Hi, thanks for your input! I've actually been working on a synonym class for this, but I think you're on to something with extending it to cover phrasing too. I like the idea of randomly altering the way the data is delivered too. It'd be a blow to extensibility, but if I made a generic enough version of the algorithm it should solve most of those problems.

Have you ever seen Dwarf Fortress' descriptions? Impressive stuff, but even they feel a little bit contrived after a while.

An example description:

[img]http://manvshorse.files.wordpress.com/2008/06/dwarf-fortress-2.jpg[/img]
May 15, 2012 06:16 PM
Servant of the Lord
Never played Dwarf Fortress for longer than five minutes (would require too much time for me to get over the learning curve).

Yeah, reading that example, their results seem to be not so great (but maybe that's a one-off case?). The three repeated uses of "lately" in the first paragraph set the tone for the rest of the content, and the [b][i]nine[/i][/b] occurances of "She is..." bring the whole description to a clumsy close. One of the first lessons writers learn is to not re-use the same words multiple times in too close proximity (Note: I am not a writer). It seems any system you create might have to take that into account... (like that synonym class you mentioned).

I think the biggest problem with the Dwarf Fortress example you posted is the same problem as your journal entry: that each bit of data is it's own sentence. The Dwarf Fortress example has some lists, "<name> likes <list>", which slightly helps, but until the sentences are able to run smoothly together (while also avoiding run-on sentences), it'll feel too contrived.

Sounds like a fun challenge, actually! Not math heavy, and a simple problem to describe (but medium to hard to solve), so it's easy to tell if you are improving or degrading your results as you iterate. As you work on it, it'd be a good idea to pick a real writer's mind, and run through the idea and show to them some 'ideal' output vs real output for their ideas and suggestions.

I half want to tackle the challenge myself, despite having no experience in the area.
May 16, 2012 06:35 PM
cgpIce
I really love what you have here, its well thought out and overall very pleasing, I do like the idea of some randomization in the way the message is told. In Short [b]well done![/b]
May 17, 2012 01:45 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement