ID:145455
 
Code: Map generator, using Jp's MakeDundgen() proc in his.
mob
verb
Make_Map()
MakeDungeon()


Problem description: Forget those Lag testing hubs, this is the real deal - It practicily DESTORYS Dream Seeker, while the same thing is a breeze for the actual file it came from.

Glad to see someone is using my library. :P

The problem is the lack of arguments, I believe. Let me just pull up the source file for the library...

Yeah, it's the lack of arguments. Just to copy the commented-out help file inside the library, which should probably go in some sort of web-page:
MakeDungeon() has 15 arguments, and probably wins the 'Procedure with most arguments' award.

They are, in order: x, y, z, floortype, walltype, iterations, rminx, rmaxx, rminy, rmaxy, minx, maxx, miny, maxy, repeatlimit.

All of them are also neccessary.

x and y are the 'starting coordinates' for the first room you want to put down. z is the z-level
you are mapping on.

Floortype is the 'floor' type that you are using for this map.

Walltype is the 'wall' type for the map that you are mapping on.

Iterations is the number of rooms the generator will make, but it may end up making less
then that number, for various reasons.

rminx and rmaxx specify the minimum and maximum x-dimensions for a room.

rminy and rmaxy specify the minimum and maximum y-dimensions for a room.

minx, maxx, miny and maxy specify the minimum and maximum x and y values that the function
should map on. It won't touch any turfs with x or y values lower or higher then these.

Repeatlimit is the number of times it should try generating a room before giving up, and
declaring the map filled to the point where no more rooms can be made.


Of course, making large maps will make it slow down, but not too much. The longest wait I've seen was about 10 seconds or so, and that was a pretty big map.

I should add some ASSERT()s to that proc...

EDIT: And as an example, this is the actual code for the demo map-drawing procedure:
verb/DrawDungeon()
loc=locate(500,500,1)
var/numsteps=input(src,"Number of iterations?","Iterations",500) as num
var/rminx=input(src,"Minimum x-size of rooms?","Rooms",0) as num
var/rmaxx=input(src,"Maximum x-size of rooms?","Rooms",5) as num
var/rminy=input(src,"Minimum y-size of rooms?","Rooms",0) as num
var/rmaxy=input(src,"Maximum y-size of rooms?","Rooms",5) as num
var/repeat=input(src,"Repeat-limit?","Limit",10) as num
MakeDungeon(500,500,1,/turf/floor,/turf/wall,numsteps,rminx,rmaxx,rminy,rmaxy,1,world.maxx,1,world.maxy,repeat)
In response to Jp
I did that before (Apart from I put the whole code into a new file) but it didn't work. Testing again...


I bet a lot more are, but they claim it as their own. <_<

EDIT - Still a murderer.

mob
verb
Make_Map()
MakeDungeon(200,200,1,/turf/floor,/turf/wall,12,0,9,0,9,1,world.maxx,1,world.maxy,2)

It was adjusted to fit in with my game size.
In response to RedlineM203
I bet a lot more are, but they claim it as their own. <_<

Eh. I know I wrote it. :P.

EDIT - Still a murderer.

Hmmm... Strange. Those arguments should work.

Is the area you're mapping all /turf/wall? I can't see any reason why it would lag to all hell if it wasn't, but still...
In response to Jp
Well, heres the Turf tree...

turf
icon = 'Turf.dmi'
floor
wall
icon_state = "Wall"
density = 1


They DID have caps to start, but I got rid of them for it.

Oh, and Loop check is off. Its very annoying when you don't want it.
In response to RedlineM203
I meant, is the area you're mapping onto all '/turf/wall'?

Also, you've said that you copied the code over. Does that mean you grabbed the code from the library, and copy/pasted it in? In that case, make sure you got ALL the procs there. Specifically, the ones you need are:

-GenRect()
-IsValidRect()
-MakeDungeon()(duh)

Also, it could be something to do with the verb name, though I doubt it. Try renaming it, just in case it is interacting with the MakeMap() proc in an interesting fashion.
In response to Jp
I did that, trying again...


Fail. Sorry Jp, I might have to settle for another Map Gen. :(
In response to RedlineM203
Alright. This is getting weird.

I'm going to ask if you could do some serious debugging. Could you replace the 'MakeDungeon()' proc you copied with this one, and then run it, outlining the results?

proc/MakeDungeon(var/x,var/y,var/z,var/floortype,var/walltype,var/iterations,var/rminx,var/rmaxx,var/rminy,var/rmaxy,var/minx,var/maxx,var/miny,var/maxy,var/repeatlimit)
var/list/turf/posswalls=list()
world << "Placing first room"
while(!posswalls.len)
posswalls=GenRect(rand(-rmaxx,-rminx)+x,rand(-rmaxy,-rminy)+y,rand(rmaxx,rminx)+x,rand(rmaxy,rminy)+y,z,floortype,walltype,posswalls)
world << "posswalls.len = [posswalls.len]"
sleep(1)
world << "Done. Entering main loop"
var/xsize
var/ysize
var/turf/t
var/x1
var/y1
var/x2
var/y2
var/n
var/cx
var/cy
var/xpat=0
var/ypat=0
var/repeats
var/end=0
for(var/i=1 to iterations)
world << "Iteration [i]"
sleep(1)
xpat=0
ypat=0
n=0
repeats=0
while(!n)
world << "Entering possible-room generator"
sleep(1)
if(repeats>=repeatlimit)
end=1
break
repeats++
t=pick(posswalls)
xsize=rand(rminx,rmaxx)
ysize=rand(rminy,rmaxy)
switch(rand(1,4))
if(1)
x1=t.x-0.5*xsize
x2=t.x+0.5*xsize
y1=t.y+1
y2=t.y+1+ysize
cx=t.x
cy=t.y
xpat=1
ypat=1

if(2)
x1=t.x-0.5*xsize
x2=t.x+0.5*xsize
y1=t.y-1
y2=t.y-1-ysize
cx=t.x
cy=t.y
xpat=1
ypat=-1

if(3)
x1=t.x+1
x2=t.x+1+xsize
y1=t.y-0.5*ysize
y2=t.y+0.5*ysize
cx=t.x
cy=t.y
xpat=1
ypat=1
if(4)
x1=t.x-1
x2=t.x-1-xsize
y1=t.y-0.5*ysize
y2=t.y+0.5*ysize
cx=t.x
cy=t.y
xpat=-1
ypat=1
x1=round(x1)
x2=round(x2)
y1=round(y1)
y2=round(y2)
if(IsValidRect(x1-xpat,y1-ypat,x2+xpat,y2+ypat,1,walltype,minx,maxx,miny,maxy))
n=1
world << "Valid room found."
sleep(1)
if(!end)
posswalls=GenRect(x1,y1,x2,y2,z,floortype,walltype,posswalls)
world << "Room placed"
new floortype (locate(cx,cy,1))
sleep(1)
end=0
world << "Done"


I'm looking for the output. It should help me figure out where the problem is.
In response to Jp
Wow.. it works now. ish.


posswalls.len = 0

            MakeDungeon(200,200,1,/turf/floor,/turf/wall,12,1,8,1,8,1,world.maxx,1,world.maxy,0)
In response to RedlineM203
It just outputs that, repeatedly?
In response to Jp
Yeah.
In response to RedlineM203
Does the GenRect() proc you have look EXACTLY like this one?

proc/GenRect(var/x1,var/y1,var/x2,var/y2,var/z,var/floortype,var/walltype,var/list/posswalls)
for(var/turf/t in block(locate(x1,y1,z),locate(x2,y2,z))) new floortype(t)
for(var/turf/t in block(locate(x1,y1,z),locate(x2,y2,z)))
if(istype(t,floortype))
for(var/turf/t2 in list(get_step(t,NORTH),get_step(t,EAST),get_step(t,SOUTH),get_step(t,WEST)))
if(istype(t2,walltype)&&!(t2 in posswalls))
posswalls+=t2
break
return posswalls


My thoughts are that you may have downloaded an earlier version of the library, and because you copied it over instead of using the include function, it didn't get updated. Possibly there were bugs.
In response to Jp
I got the latest version it seems, it does the same either way.
In response to RedlineM203
Strange. Could you try this in place of your GenRect() proc?

proc/GenRect(var/x1,var/y1,var/x2,var/y2,var/z,var/floortype,var/walltype,var/list/posswalls)
for(var/turf/t in block(locate(x1,y1,z),locate(x2,y2,z))) new floortype(t)
for(var/turf/t in block(locate(x1,y1,z),locate(x2,y2,z)))
world << "Bing"
sleep(1)
if(istype(t,floortype))
world << "Bingely"
sleep(1)
for(var/turf/t2 in list(get_step(t,NORTH),get_step(t,EAST),get_step(t,SOUTH),get_step(t,WEST)))
world << "Ping"
if(istype(t2,walltype)&&!(t2 in posswalls))
posswalls+=t2
world << "Kaching!"
sleep(1)
break
return posswalls


And are you ABSOLUTELY SURE that you're mapping over an area composed ENTIRELY of whatever walltype is? Because if you aren't, it won't work.
In response to Jp
Placing first room
posswalls.len = 0
posswalls.len = 0
posswalls.len = 0
posswalls.len = 0
posswalls.len = 0
posswalls.len = 0


What do you mean, does the map have to be all walls? Crap...

EDIT: Still don't work.