Author Topic: Map Generation / Tile definition?  (Read 29953 times)

Shaggy

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
  • (╯°□°)╯︵ ┻━┻ <( !@#$ THIS, I'M OUT. )
    • View Profile
    • Not Quite ADoM
    • Email
Map Generation / Tile definition?
« on: October 02, 2009, 09:33:02 PM »
How do you guys define your maps/tiles, if you do? I'm working on my first ever RL right now, and I'm not sure whats the 'best' way or most efficient way to do it.
Right now I'm just reading my maps from a text file and coloring them accordingly, with no real definition or class for tiles. I'm thinking I'm gonna have to change that soon, especially when I write my random dungeon generator for the dungeons..

What are your thoughts?
Check out my blog at http://NotQuiteADoM.blogspot.com/ !

Numeron

  • Rogueliker
  • ***
  • Posts: 88
  • Karma: +0/-0
    • View Profile
    • Numeron Reactor
Re: Map Generation / Tile definition?
« Reply #1 on: October 03, 2009, 12:44:09 PM »
There are more complex and infact better ways of doing this, but this is a simple one that I have used before, because I wasnt coding for growth, and good enough to work was good enough. I recommend you follow that mentality if this is your first project, you should use the opportunity to learn how to do it better next time :)

I have a Tile class which contains the isTransparent and isPassable booleans, and the character and colour variables. I create a few of these, most importantly one Floor and one Wall object which set their appropriate flags. My map generation algorithm fills a 2d array with references to these objects (dont bother creating more than one of each, its not nessecary). then your monsters and hero can go into an array which sits next to that one. each moster stores its location, so when you move them around you check against the isPassable boolean of the appropriate spot on the map and check if there is a monster in the tile you are trying to move into. All this goes into a Map class.

An array of maps, and a few methods about the place to move your hero between the maps when you activate stairs and for other such things and you're set :D

How to generate random maps is another story, but http://roguebasin.roguelikedevelopment.org/index.php?title=Articles#Map has some recommended readings

-Numeron

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: Map Generation / Tile definition?
« Reply #2 on: October 03, 2009, 11:17:13 PM »
Although I think an array of a small class is the best solution, I usually just end up using an array of integers. Something like:

int map[80][25][3];

With the 3rd dimension being: 0 - Character 1 - Type (Usually just wall/floor) 2 - Misc (color, seen before, etc.). But really, I've regretted doing this in every long term project I've done it in. It's much more convenient to use a class.

Perdurabo

  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
    • Email
Re: Map Generation / Tile definition?
« Reply #3 on: October 03, 2009, 11:19:54 PM »
Although I think an array of a small class is the best solution, I usually just end up using an array of integers. Something like:

int map[80][25][3];

With the 3rd dimension being: 0 - Character 1 - Type (Usually just wall/floor) 2 - Misc (color, seen before, etc.). But really, I've regretted doing this in every long term project I've done it in. It's much more convenient to use a class.

I go with Elig here - arrays are much handier to use. In Kharne, I have the following:

  { Map Layer Definitions }
  Visible: array[1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Terrain: array [1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Effects: array[1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Objects: array [1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Zone: array [1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Monsters: array [1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  Walkable: array [1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of boolean;
  People: array[1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;
  TerrainCost: array[1..DUNGEONSIZEX, 1..DUNGEONSIZEY] of integer;



Numeron

  • Rogueliker
  • ***
  • Posts: 88
  • Karma: +0/-0
    • View Profile
    • Numeron Reactor
Re: Map Generation / Tile definition?
« Reply #4 on: October 04, 2009, 02:46:27 AM »
you have a 2d array of objcts? as in swords and boots and stuff? how then would drop more than one item into onto a tile?

Perdurabo

  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
    • Email
Re: Map Generation / Tile definition?
« Reply #5 on: October 04, 2009, 06:36:48 AM »
you have a 2d array of objcts? as in swords and boots and stuff? how then would drop more than one item into onto a tile?

Linked list basically.

Each item object has an integer that points to the next item object on the tile. And so on and so on until the last item object on the tile has a -1 for this.


purestrain

  • Rogueliker
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
Re: Map Generation / Tile definition?
« Reply #6 on: October 04, 2009, 08:53:45 AM »
Hi,

i usually prefer a object for each tile like
Code: [Select]
Tile {
  byte relX;
  byte relY;
  unsigned int miscFlags;
  bool isWall() { return miscFlags & 0x00001; }
  ...
  Area parentArea;
}

whereas each Tile belongs to a higher level area (room, corridor) with its relative coordinates to the upperleft corner of the area. This allows you to build dungeons with arbitary sizes/shapes much more easily.

But for your first roguelike you should go with a simple 2d array, maybe with structs/classes or just pain integers which hold Bit-Combinations.


Etinarg

  • Rogueliker
  • ***
  • Posts: 424
  • Karma: +1/-1
  • Idea archivist and game tinkerer.
    • View Profile
    • Gedankenweber Blog (German)
Re: Map Generation / Tile definition?
« Reply #7 on: October 05, 2009, 09:23:34 AM »
you have a 2d array of objcts? as in swords and boots and stuff? how then would drop more than one item into onto a tile?

I sometimes think it's not needed. The old roguelikes worked with one item per tile. It was a problems sometimes, but not too often. Lately I think the added development overhead for more then one item per tile is not worth the little gain in gameplay value.

I'd rather think of it as a restriction, like inventory limits, that imposes tactical decisions on the player.

jaydg

  • Rogueliker
  • ***
  • Posts: 54
  • Karma: +0/-0
    • View Profile
    • NLarn Homepage
Re: Map Generation / Tile definition?
« Reply #8 on: October 05, 2009, 09:52:31 AM »
I sometimes think it's not needed. The old roguelikes worked with one item per tile. It was a problems sometimes, but not too often. Lately I think the added development overhead for more then one item per tile is not worth the little gain in gameplay value.

Larn for example has this restriction. I found it so ridiculous that I started to reimplement it.
There some places in the Larn code where generated items get thrown away because no free place can be found. On the other hand it looks really funny when the loot dropped when a monster gets killed keeps flying around.

I needed an inventory for the player, thus I implemented it. The pile of items on the floor,  the monster inventories  and the player's inventory share 100% code. When I add a feature, all benefit. Thus I had no overhead by adding more advanced features.

Shaggy

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
  • (╯°□°)╯︵ ┻━┻ <( !@#$ THIS, I'M OUT. )
    • View Profile
    • Not Quite ADoM
    • Email
Re: Map Generation / Tile definition?
« Reply #9 on: October 05, 2009, 09:55:46 AM »
I just use a 2d array of integers that point to a tile structure.
so the map might actually look something like
000000000
022222220
021111120
011111120
011111120
021111120
022222220
000000000

and display

 ########
 # . . . . . . . #
 # . . . . . . . #
 # . . . . . . . #
 # . . . . . . . #
 # . . . . . . . #
 # . . . . . . . #
 ########

Check out my blog at http://NotQuiteADoM.blogspot.com/ !

magellan

  • Rogueliker
  • ***
  • Posts: 91
  • Karma: +0/-0
    • View Profile
    • Email
Re: Map Generation / Tile definition?
« Reply #10 on: October 05, 2009, 11:32:17 AM »
Yep, that or make a 2D array of tile structures.
advantage of 1)
Less memory used
advantage of 2)
You can change some property of a tile without changing that tile worldwide

But: I am wondering: (Not to you shaggy, to all the smart people here)
Why would you want to tie your items to tiles?

I do it like this: there is a list with all items currently existing in the game, and when i load a level i generate a shorter list with the location of each item on the long list, that also happens to be on the same level (Not necessary, just to make it a little faster when there are a lot of items, because you do have to go through each item every step to check if its under a player, or monster etc.)
Items have coordinates, and if 99999.3 have the same, the tile that happens to be in that position doesn't even need to know about it.
Anything glaringly bad about that approach? 

Ohoh.... and i have been wondering:
Doors: Items or Tiles? Your arguments concerning the age old debate? :)

Etinarg

  • Rogueliker
  • ***
  • Posts: 424
  • Karma: +1/-1
  • Idea archivist and game tinkerer.
    • View Profile
    • Gedankenweber Blog (German)
Re: Map Generation / Tile definition?
« Reply #11 on: October 05, 2009, 12:59:19 PM »
Doors: Items or Tiles? Your arguments concerning the age old debate? :)

There is more than tiles and items in a gridded world :)

In my last project I had grounds, features, and objects. Features were fixed, but active game elements, objects were mobile game elements. Doors were features then. Items and monsters were objects.

Actually a door was three "features", since it consisted of two door posts and the actual door. But that was just the overkill.

jaydg

  • Rogueliker
  • ***
  • Posts: 54
  • Karma: +0/-0
    • View Profile
    • NLarn Homepage
Re: Map Generation / Tile definition?
« Reply #12 on: October 05, 2009, 01:29:39 PM »
Ohoh.... and i have been wondering:
Doors: Items or Tiles? Your arguments concerning the age old debate? :)

Like Hajo writes: a third category for stationary stuff. This is an integer value which is linked to a lookup table. In this table the attributes for the element as description, color, transparency and  "image" are stored.

In this category are also fountains, statues, building entrances and the like. A door is either a closed door or an open door. Both of them are represented by different ids, which makes them independent of each other. This approach allows to drop stuff in the opened door, which makes it impossible to close it. Or to blow the door away by simply setting the id of the third category to 0.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Map Generation / Tile definition?
« Reply #13 on: October 05, 2009, 02:19:34 PM »
I haven't tied items to tiles either. Items are in large level list (could be slow) and item map has only the frame id for faster output (one map layer is for items). When item is moved, picked up etc. the map is updated for that item.
Other objects work the same way, they are not part of the map, but stored in level class. If anything complex is planned for objects like doors it's best to make them real objects and not just simple variables in array.

Etinarg

  • Rogueliker
  • ***
  • Posts: 424
  • Karma: +1/-1
  • Idea archivist and game tinkerer.
    • View Profile
    • Gedankenweber Blog (German)
Re: Map Generation / Tile definition?
« Reply #14 on: October 05, 2009, 02:23:56 PM »
If anything complex is planned for objects like doors it's best to make them real objects and not just simple variables in array.

Implement a chat bot, and make speaking doors ;) Also give them an emotion model, and if  the door is sulky, angry at you or just snappy today, it won't open for you.

Question is, how to bribe a sulky door to open for you ;D
« Last Edit: October 05, 2009, 02:25:45 PM by Hajo »