Thursday, November 24, 2016

Spaceship random generation

Disclaimer: a roguelike is a genre of games where characters are used for visual representation of game world. I've made few roguelike too: CryptoRL and CryptoRl2.

Spaceship generation

I'm working on a small prototype of spaceship room generator. What does it mean ?
Imagine a spaceship like Enterprise or Galactica, from a top/down perspective. A spaceship is made of different kind of rooms types: engine room, dormitory room, armoury room and so on. It's like a dungeon in fantasy games, where every room can be used by crew for a specific need or function.

Different kind of algorithms

There are a lot of different kind of algorithms out there, here some ideas:

Random walk: works fine for cave-based dungeons (I've used this for CryptoRL2), but not so cool for ships, because is too unpredictable and can create small corridors with awkward turns. I think is fine for cave dungeons, but need more work on it. Pure cellular automata feel, at least for me, like I'm missing something, some "crucial points"

Grid based dungeon: like in Spelunky a dungeon is just a space divided using a grid (see here and here for an introduction). On random generation, there is a random walk between "start cell" (decided from one side of the grid) and "end cell" (decided from opposite side of the grid). After that "rooms" will be placed on each cell of the grid, taken randomly from a "pool" of templates (based on a theme).
Results here is good and can be realized easily with an high degree of randomness. I think this method is more suited for a random ship-dungeon, because you can create rooms for basic system (engine, dormitory, engineering bay, escape pods, etc..) mixed with "special rooms" (captain room, stargate room, alien nest and so on) on a grid with a specific shape (square, rectangle, ellipse, with wings, Battlestar Galactica and so on) and iterate on it

Classic room/corridor: place rooms randomly and connect them using corridors. I don't really like this way for my theme, what do you think about it?

Bsp: I think with my theme is fine, but I need to use "square splitting" strategy and will be become like grid based dungeon, more or less.

 Grid based random generation

My solution is based on grid based one, using following room types (remember, i'ts a roguelike!) as string:

    RANDOM_WALK = '#';
    NONE = ' ';
    EMPTY_ROOM = 'e';
    ENGINE_ROOM = 'n';
    LAB_ROOM = 'l';
    PRISON_ROOM = 'p';
    ARMORY_ROOM = 'a';
    FARM_ROOM = 'f';
    STORAGE_ROOM = 's';
    CORE_ROOM = 'c';
    AI_ROOM = '!';
    CHAPEL_ROOM = '*';
    ROBOT_ROOM = 'r';

    KEY = 'K';
    DOOR = 'D';

I'm using also a template for ship generation, so every random generation will generate rooms inside that template (a 10x10 grid), where 'e' means that is possible to place a room type into that space:

  ee    ee 

The proposed method divide the ship in three part: up (u), middle (m) and lower (l), in the following way:

  ll              ll 

I'm using this information to place rooms, so for example engine rooms can be created only in the lower part or lab part only in the middle. Of course there are rooms that can be placed everywhere, like dormitory or storage room. Also following suggestion from this thread  I'm using right/left symmetry  for random generation, so with the same template and here a result:

  bs   || 
and after filling right part with mirror information from the left one a random generated spaceship:

  bs    sb 

With a little bit of legend can have more meaning:

f = farm
s = storage room
d = dormitory
p = prison room
c = core room
b = landing bay

As you can see in this example, this ship seems to be a merchant ship, with a lot of storage, a landing bay for small vessels run by from main spaceship to planet and a farm.. because you want to eat something into space, right ?


I think I'm in the right way, using grid based placement, to create randomly spaceships, a perfect setting of a roguelike!
See you soon and feel free to comment if you want!

No comments:

Post a Comment