User Tools

Site Tools


lua:scripting:firetemple

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lua:scripting:firetemple [2015/01/01 08:45] – created vodurlua:scripting:firetemple [2015/01/01 09:50] (current) vodur
Line 1: Line 1:
 +Build 5x5 grid.
 <code lua> <code lua>
 do do
Line 48: Line 49:
     end     end
 end end
 +
 +end
 +</code>
 +
 +Print map
 +<code lua>
 +do
 +
 +local cols=5
 +local rows=5
 +local basevnum=501
 +
 +local function getvnum( col, row)
 +    return basevnum-1 + (row-1)*cols + col
 +end
 +
 +local function setexflag( dir, flg)
 +    if not(mob.room[dir]:flag(flg)) then
 +        olc(dir.." "..flg)
 +    end
 +end
 +
 +local out={}
 +
 +for row=1,rows do
 +    local second={}
 +    for col=1,cols do
 +        table.insert(out, "#")
 +        local room=getroom(getvnum(col,row))
 +        
 +        if room.east then
 +            table.insert(out, room.east:flag("dormant") and " " or "-")
 +        end
 +        
 +        if room.south then
 +            table.insert(second, room.south:flag("dormant") and " " or  "| ")
 +        end
 +    end
 +    table.insert(out,"\n\r"..table.concat(second).."\n\r")
 +end
 +
 +sendtochar(mob, table.concat(out))
 +
 +end
 +</code>
 +
 +Generate maze
 +<code lua>
 +do
 +
 +local function revdir( dir )
 +    if dir == "north" then return "south"
 +    elseif dir == "south" then return "north"
 +    elseif dir == "east" then return "west"
 +    elseif dir == "west" then return "east"
 +    end
 +end
 +
 +--Randomized Prim's algorithm http://en.wikipedia.org/wiki/Maze_generation_algorithm
 +local walls={}
 +local maze={}
 +
 +for k,v in pairs(getroom(501).exits) do
 +    table.insert(walls, { dir=v, exit=getroom(501)[v]} )
 +end
 +
 +while #walls>0 do
 +    local wallind=randnum(1,#walls)
 +    local wall=walls[wallind]
 +    table.remove(walls, wallind)
 +    
 +    if not maze[wall.exit.toroom] then
 +        wall.exit:setflag("dormant", false)
 +        wall.exit:setflag("door", false)
 +        wall.exit.toroom[revdir(wall.dir)]:setflag("dormant", false)
 +        wall.exit.toroom[revdir(wall.dir)]:setflag("door", false)
 +        maze[wall.exit.toroom]=true
 +        for k,v in pairs(wall.exit.toroom.exits) do
 +            table.insert(walls, { dir=v, exit=wall.exit.toroom[v]} )
 +        end
 +    end
 +    
 +    
 +                   
 +end
 +
  
 end end
 </code> </code>
lua/scripting/firetemple.1420101955.txt.gz · Last modified: 2015/01/01 08:45 by vodur