Author Topic: Need some help... With a MapGen algorithm.  (Read 26494 times)

Valhalla

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
  • Headphones <3
    • View Profile
    • Team 3 Software (Coming Soon...)
    • Email
Need some help... With a MapGen algorithm.
« on: July 11, 2008, 09:21:00 AM »
Okay, so, I've got this neat-o idea for making a graphical user interface for a roguelike. BUT, there's a problem: I can't figure out how to generate maps!

I'm using a version of BASIC where, if I had a map generator, I could easily convert it, but I don't even know where to find a BASIC roguelike that is also open-source, but also, just the map generating code would be excellent help.

Anyways, now that I've told you my problem, here's some info about the game:

It's a GUI-based roguelike, but it is unlike most roguelikes with GUIs, mainly because the GUI is rendered using OpenGL (Yeah, it's a 3D dungeon viewer basically).

It's not a huge project, but I've been off and on with it for a few months now, and I'm about ready to start developing on this thing a bit more. If I had a way to generate a real map, I'd show you guys what it looks like, but right now I'm having to manually enter map codes.

The map engine I'm really wanting is something similar to NetHack. If that is at all possible, I'd greatly appreciate the help.

Anyways, thanks ahead of time. This has been a real pain, and I figured the best place to ask was here.

Anvilfolk

  • Rogueliker
  • ***
  • Posts: 374
  • Karma: +0/-0
    • View Profile
Re: Need some help... With a MapGen algorithm.
« Reply #1 on: July 11, 2008, 01:42:22 PM »
I can't honestly tell you anything concrete, but check out all the roguelikes that have been mentioned around this forum. A lot of them are open-source, and you can just skip most of the code and check the mapgen algorithms. The Roguelikelib comes to mind, I think it had a couple of generators!

None of them are in BASIC, as far as I know, but you should be able to understand them if you have a good grip on programming.

Also: do you NOT want to make maps, or do you have no ideas, but want some so you can develop map generators according to those ideas/techniques?
"Get it hot! Hit it harder!!!"
 - The tutor warcry

One of They Who Are Too Busy

Valhalla

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
  • Headphones <3
    • View Profile
    • Team 3 Software (Coming Soon...)
    • Email
Re: Need some help... With a MapGen algorithm.
« Reply #2 on: July 12, 2008, 06:34:23 AM »
Well, I want to make maps using a generator, but I've never coded a true NetHack styled generator. I could easily learn how to make one, if I had the source to one. So I guess I'm going on a roguelike hunt.

And yeah, I understand quite a few languages, like C++, BASIC, OpenGL (Which a lot of the GUI is written in), and I'm new to, but know a little bit of, PHP, Java and Ruby. I mean, not to boast, but it's not like I'm extremely good in all of those. I simply tried to specialize in many languages, because a lot of times I find myself working bugs out of code for other people.

Well, thanks for the help. If anyone else has some ideas on where to get something worth looking at, I'm still interested. As for now, I'm off to browse for open-source roguelikes.

Thx

ido

  • Rogueliker
  • ***
  • Posts: 618
  • Karma: +0/-0
    • View Profile
    • Tame Tick
Re: Need some help... With a MapGen algorithm.
« Reply #3 on: July 12, 2008, 11:26:08 AM »
There are a ton of them, one example is the very simple generator in my game (cryptrover, written in c but if you know c++ you should be able to understand most of it):

http://code.google.com/p/cryptrover/source/browse/trunk/src/map.c

start from the bottom, at the init_map function.  It starts with a map full of WALL tiles and digs rooms and corridors between them.  The los function (reused from my line-of-sight code) can be found here:

http://code.google.com/p/cryptrover/source/browse/trunk/src/utils.c

-Ido.

Valhalla

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
  • Headphones <3
    • View Profile
    • Team 3 Software (Coming Soon...)
    • Email
Re: Need some help... With a MapGen algorithm.
« Reply #4 on: July 12, 2008, 11:39:02 AM »
Wow, neat-o. This source code you have here gave me an idea for a map generator similar to NetHack, but... Hmm...

I think I might have what I need. Let me see what I can do now.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Need some help... With a MapGen algorithm.
« Reply #5 on: July 13, 2008, 11:28:46 AM »
Post some screen shots, and/or your algorithm and we could give you some feedback if you need it.
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Anvilfolk

  • Rogueliker
  • ***
  • Posts: 374
  • Karma: +0/-0
    • View Profile
Re: Need some help... With a MapGen algorithm.
« Reply #6 on: July 13, 2008, 10:05:22 PM »
Also, do you know Tower? It's precisely a 3d roguelike! You might want to check it out!
"Get it hot! Hit it harder!!!"
 - The tutor warcry

One of They Who Are Too Busy

Valhalla

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
  • Headphones <3
    • View Profile
    • Team 3 Software (Coming Soon...)
    • Email
Re: Need some help... With a MapGen algorithm.
« Reply #7 on: July 14, 2008, 05:03:17 AM »
Never heard of Tower, but I've used Falcon's Eye for NetHack and I didn't like it. What I'm doing looks like NetHack with the tiles at an angle and actual height to them (i.e. walls, character height)

Here's a screen of the Room Generator. I can't get pathmaking to work, but I'm working on it! I'll get it sooner or later.

http://www.team3soft.com/3dhackscr1.PNG

Also, I'm working on a simple tilebased roguelike with my friend that uses a map generator, but it's got not rooms, just paths and stuff.

But I'd really like to figure these paths out. I have an idea, and I'm about to try it. Wish me luck.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Need some help... With a MapGen algorithm.
« Reply #8 on: July 14, 2008, 07:54:38 AM »
I could easily learn how to make one, if I had the source to one.

You still need to understand the algorithm of the generator. When you do that you don't need a source code to make one. If you actually had tried to create a generator then you would soon learn what makes it work and how it can fail.

Anvilfolk

  • Rogueliker
  • ***
  • Posts: 374
  • Karma: +0/-0
    • View Profile
Re: Need some help... With a MapGen algorithm.
« Reply #9 on: July 14, 2008, 12:52:40 PM »
That's true. The idea is all you need, and maybe it won't make a Nethackish map, but so what? The only mapgen I made (and it was incomplete) was really simple. I had the grid at height 128 (it went from 0 to 255) - then I'd pick several random spots, chose a new random height for them, and smoothed those squares with the rest of the terrain using simple sine or cosine functions. You'd get a hilly terrain.

Anyway, I found Tower's site for you: http://tower.sourceforge.net/
"Get it hot! Hit it harder!!!"
 - The tutor warcry

One of They Who Are Too Busy

Valhalla

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
  • Headphones <3
    • View Profile
    • Team 3 Software (Coming Soon...)
    • Email
Re: Need some help... With a MapGen algorithm.
« Reply #10 on: July 15, 2008, 05:48:00 AM »
Well, I tried my own algorithm. In fact, I made my own:

Code: [Select]
'MAPPING SYSTEM
dim x,y,z,tiles(29)(29)
dim rooms,rx,ry,rmx,rmy,rtestx,rtesty,rcheck,door
x=0:y=int(-3):z=0
rooms=rnd()%10+1

while rooms>0
rx=rnd()%20:ry=rnd()%20
rmx=rnd()%6+5:rmy=rnd()%6+5:rcheck=0
for rtesty=ry to ry+rmy
for rtesty=ry to ry+rmy
if tiles(rtestx)(rtesty)=2 then:rcheck=1:endif
next:next
if rcheck=0 then
for rtesty=ry to ry+rmy:for rtestx=rx to rx+rmx
tiles(rtestx)(rtesty)=1:next:next
for rtesty=ry to ry+rmy:tiles(rx)(rtesty)=2:next
for rtesty=ry to ry+rmy:tiles(rx+rmx)(rtesty)=2:next
for rtestx=rx to rx+rmx:tiles(rtestx)(ry)=2:next
for rtestx=rx to rx+rmx:tiles(rtestx)(ry+rmy)=2:next
endif:rooms=rooms-1:wend

'for y=0 to 29:for x=0 to 29
'if tiles(x)(y)=2 then:door=rnd()%25+1
'if door=25 then:tiles(x)(y)=rnd()%2+3:endif:endif
'next:next

px#=rnd()%30:py#=rnd()%30
while not tiles(px#)(py#)=1
px#=rnd()%30:py#=rnd()%30:wend
tiles(px#)(py#)=5

'PATHGEN... PART OF MAPGEN v1.0
paths=rnd()%15+5:while paths>0
while tiles(mx)(my)<>0:mx=rnd()%28+1:my=rnd()%28+1:wend
if tiles(mx+1)(my)=0 then:pathdir=0:mx=mx+1:endif
if tiles(mx)(my+1)=0 then:pathdir=1:my=my+1:endif
if tiles(mx-1)(my)=0 then:pathdir=2:mx=mx-1:endif
if tiles(mx)(my-1)=0 then:pathdir=3:my=my-1:endif
pathlength=20:while pathlength>0
pathdir=rnd()%4:pathseg=rnd()%10:while pathseg>pathlength
pathseg=pathseg-1:wend:while pathdir=0 and mx+pathseg>28
pathseg=pathseg-1:wend:while pathdir=1 and my+pathseg>28
pathseg=pathseg-1:wend:while pathdir=2 and mx-pathseg<1
pathseg=pathseg-1:wend:while pathdir=3 and my-pathseg<1
pathseg=pathseg-1:wend
while pathdir=0 and pathseg>0
pathlength=pathlength-1:tiles(mx)(my)=1:pathseg=pathseg-1:mx=mx+1
if tiles(mx+1)(my)=2 then:tiles(mx+1)(my)=3:pathseg=0:endif:wend
while pathdir=1 and pathseg>0
pathlength=pathlength-1:tiles(mx)(my)=1:pathseg=pathseg-1:my=my+1
if tiles(mx)(my+1)=2 then:tiles(mx)(my+1)=3:pathseg=0:endif:wend
while pathdir=2 and pathseg>0
pathlength=pathlength-1:tiles(mx)(my)=1:pathseg=pathseg-1:mx=mx-1
if tiles(mx-1)(my)=2 then:tiles(mx-1)(my)=3:pathseg=0:endif:wend
while pathdir=3 and pathseg>0
pathlength=pathlength-1:tiles(mx)(my)=1:pathseg=pathseg-1:my=my-1
if tiles(mx)(my-1)=2 then:tiles(mx)(my-1)=3:pathseg=0:endif:wend:wend
paths=paths-1:wend
'PATHGEN OVER
'END OF MAPPING SYSTEM

I'm a terribly sloppy coder >_> But as long as I understand the code, it's fine for now, since this is not Open-Source.

Of course, what I meant is that I need to find one similar to NetHack, because that one isn't working for the game.

And this game Tower looks neat. I'd download it, but 12megs is a lot to download on my dialup :(