• Register
Post news Report RSS A new architcture for the monster generator

This week, I give a more detailed insight in how the monster generator is organized

Posted by on

Hi all! I'm happy to tell you that I'm finally back on track, working again on Olvand's next update. The last few blogposts, I mostly told you about what exactly is in these updates, and why. This week, I would like to take a slightly different approach, and tell you about the code architecture. This is because I've spent a lot of time working on integrating the [monster generator] into the game, and I ended up doing it in a much more generic, elegant way than I originally imagined.

The original plan and its downsides

The code for the monster generator already seemed largely finished when I wanted to start integrating it: it could generate monsters with various appearances, various colors, from various sides, and also 'summarize' its creations in 8-character strings, so they could easily be sent around the internet.


My original plan was to simply add this generator to the Olvand repository, and then link to it from other parts of the game. For example, when the server generates a cave, it asks the monster generator for a few 8-character strings that represent monsters, and when the client needs to turn these representations into actual graphics, it again asks the monster generator to do so.

However, there were two main downsides to the original implementation:

* The generator was not easily extendible: adding new bodies, bodyparts, colors, etc. always meant fiddling with the code. While that is not that problematic right now, now I remember how everything works, it will be when I return to this code in, say, 2 years. But more importantly, it won't allow people without access to the source code (=everybody except me) to extend the generator. Over the last few years, I've grown more and more enthousiastic about content creation by the players; it's definitely something I would want to encourage. Closing the whole thing off right now already would be completely opposite to that.

* The generator could only be used for monsters. Just like the fish generator could only be used for fish, the original monster generator could only be used for monsters, despite there being a lot of overlap in their functionality. This is a particularly stupid thing to do because I already have a -spoiler!- fruit generator planned for the next update.

The new architecture

So the new plan is something that can be (1) used for anything and (2) extended without programming. I achieved this with a combination of a special folder structure in combination with JSON configuration files. To understand how that works exactly, you have to realize that all of Olvand's generators work in roughly this way:

1. A base image is chosen
2. "Bodyparts" are merged with this base image
3. The whole thing is recolored


And in the case of the monsters, this has to be done for all positions the monster can be in (looking down, walking west, lying death, etc.). This leads to this folder structure:

code:
Base A
* Side a
  * Bodypart type I
    * Option 1.png
    * Option 2.png
  * Bodypart type II
    * Option 1.png
    * Option 2.png
* Side b
  * Bodypart type I
    * Option 1.png
    * Option 2.png
  * Bodypart type II
    * Option 1.png
    * Option 2.png
Base B
* Side a
  * Bodypart type I
    * Option 1.png
    * Option 2.png
  * Bodypart type II
    * Option 1.png
    * Option 2.png
* Side b
  * Bodypart type I
    * Option 1.png
    * Option 2.png
  * Bodypart type II
    * Option 1.png
    * Option 2.png

 

And obviously, in this example there are only two options for everything, but this can be extended to infinity by simply creating more folders.

So there you have it, a nice and easy system to generate monsters, and anything really. I have to admit the actual system is slightly more complicated, because it also covers animation, but this is not much more than editing a JSON file in the top folder. This is also where you can specify which colors can be varied, and to what extent. Anyway, right now, I'm pretty happy it, and I will be even more when it's time to build the fruit generator!

If you want more development, see [twitter] or [facebook]. If you want to be a tester, you can subscribe on[olvand.com].

Post comment Comments
Twillypop
Twillypop - - 149 comments

Ah cool. Now the variety will be much more apparent. Nice job and keep at it :)

Reply Good karma Bad karma+2 votes
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: