doSpeedWalk() run command, like that used in Aardwolf, and possibly other muds.

All and any discussion and development of the Mudlet Mapper.
Post Reply
jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

doSpeedWalk() run command, like that used in Aardwolf, and possibly other muds.

Post by jieiku » Sun Mar 24, 2019 8:48 pm

convert a series of directions into a single run command. Aardwolf supports this type of navigation and im guessing other muds probably do as well.

This is the custom doSpeedWalk script that I wrote to handle this. This should be considered BETA (work in progress). I already noticed that it does not open the doors, so I will likely add that next, otherwise you may need passdoor spell.

EDIT: I have found a couple bugs and am continually improving this, will post updates every so often.

updated 4/22/19:
Code: [show] | [select all] lua
function doSpeedWalk()
  if #speedWalkPath == 0 then
    aard.log:error("No speedwalk path found!")
  end
	
	local exits = aard.map:getAllExits(aard.map.current_room)
  local path = {}
	local previousID = aard.map.current_room
	local shrinkExits = {north = "n", south = "s", east = "e", west = "w", northeast = "ne", northwest = "nw", southeast = "se", southwest = "sw", up = "up", down = "down"}
	
  for i, room_id in pairs(speedWalkPath) do
    for j, exit in pairs(exits) do
      if tonumber(room_id) == exit then
				local door = checkDoor(previousID,shrinkExits[j])
				if door then
					table.insert(path, door)
				end
        table.insert(path, j)
				previousID = room_id
      end
    end
		exits = aard.map:getAllExits(room_id)
  end
	
	local run = ""
	local samedir = 1
	local es = {north = "n", south = "s", east = "e", west = "w", northeast = "ne", northwest = "nw", southeast = "se", southwest = "sw", up = "u", down = "d"}
	
	if es[path[1]] then
		run = run.."run "
	else
    if path[2] and path[3] then
    	if es[path[2]] and es[path[3]] then
    		run = run..path[1]..";run "
    	else
    		run = run..path[1]
    	end
    else
    	run = run..path[1]
    end
		table.remove(path, 1)
	end

  while path[1] do
    local dir = path[1]
    table.remove(path, 1)
		
		if dir == path[1] then--dir is same as previous direction
			samedir = samedir+1--as long as the direction is same, increment a counter eg 2e 3e 4e until direction change			
		elseif samedir == 1 then--direction changed, single direction
    	if es[dir] then
    		run = run..es[dir]
    	else--only append ;run when direction was not a member of es[dir]
        if path[1] and path[2] then
        	if es[path[1]] and es[path[2]] then
        		run = run..";"..dir..";run "
        	else
        		run = run..";"..dir..";"
        	end
        else
        	run = run..";"..dir..";"
        end				
    	end			
		else--direction changed multiple in direction eg 2e 3e 4e		
    	if es[dir] then
    		run = run..samedir..es[dir]--no ; or semi colon, this one can be continuance
    	else--only append ;run when direction was not a member of es[dir]
				run = run..";run "..samedir..dir..";run "
    	end
			samedir = 1
		end
  end--while path[1]	
	run = string.gsub(run,";;",";")
	display(run)
	send(run)
end

function aard.map:getAllExits(room_id)
  local exits = getRoomExits(room_id)
  local sexits = getSpecialExitsSwap(room_id)
  return aard.map:concatTables(exits, sexits)
end

function aard.map:concatTables(table1, table2)
  local output = {}
  for i,v in pairs(table1) do
    output[i] = v
  end
  for i,v in pairs(table2) do
    output[i] = v
  end
  return output
end

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests