IRE Mapper Script - Dashing Problem

Post Reply
malaphus
Posts: 9
Joined: Mon Feb 01, 2010 11:47 pm

IRE Mapper Script - Dashing Problem

Post by malaphus » Sat Mar 24, 2012 9:49 pm

Hello,

There seems to be an issue with the speedwalking stuff in the IRE mapper script if you have sprint enabled. Basically if the final destination room is in the middle of a straight path of rooms, rather than walk you to the destination (if it were to sprint, it would run past the room), it simply moves you 1 room and thinks it's finished. So for example if the rooms are:
[a]--[c]-[d]-[e] and you start from room a and try to 'goto d', it simply moves you to room b and stops because, I think, the dashing logic is interfering somehow.

The code that I think has the problem is below, maybe someone can see a problem?

Code: [show] | [select all] lua
function doSpeedWalk(dashtype)
  resetStopWatch(speedWalkWatch)
  startStopWatch(speedWalkWatch)
  if mmp.settings["gallop"] or mmp.settings["dash"] or mmp.settings.sprint or dashtype then
    mmp.fixPath(mmp.currentroom, speedWalkPath[#speedWalkPath],
      (mmp.settings["gallop"] and "gallop") or (mmp.settings["dash"] and "dash") or (mmp.settings.sprint and "sprint") or (mmp.settings.runaway and "runaway") or dashtype)
  end

  mmp.fixSpecialExits(speedWalkDir)

  if #speedWalkPath == 0 then
    mmp.echo("Couldn't find a path to the destination :(")
    raiseEvent("mmapper failed path")
    return
  end

  mmp.autowalking = true

  -- this is a fix: convert nums to actual numbers
  for i = 1, #speedWalkPath do
    speedWalkPath[i] = tonumber(speedWalkPath[i])
  end

  if not mmp.paused then
    mmp.echon("Starting speedwalk from "..(atcp.RoomNum or gmcp.Room.Info.num).." to ") echoLink(speedWalkPath[#speedWalkPath], 'gotoRoom "' .. speedWalkPath[#speedWalkPath].. '"', 'Go to ' .. speedWalkPath[#speedWalkPath]) echo(": ")
    speedWalkCounter = 1
    if mmp.canmove() then mmp.move() else echo("(when we get balance back / aren't hindered)") end
  else
    mmp.echo("Will go to "..speedWalkPath[#speedWalkPath].." as soon as the mapper is unpaused.")
  end
end

function mmp.fixPath(rFrom,rTo,dashtype)
  local currentPath, currentIds = {}, {}
  local dRef = {["n"] = "north", ["e"] = "east", ["s"] = "south", ["w"] = "west"}
  if not getPath(rFrom,rTo) then return false end

  -- Logic: Look for a direction repeated at least two times.
  -- count the number of times it repeats, then look that many rooms ahead.
  -- if that room also contains the direction we're headed, just travel that many directions.
  -- otherwise, dash.

  local repCount = 1
  local index = 1
  local dashExaust = false
  while speedWalkDir[index] do
    dashExaust = false
    repCount = 1
    while speedWalkDir[index+repCount] == speedWalkDir[index] do
      repCount = repCount + 1
      if repCount == 11 then
        dashExaust = true
        break
      end
    end
    if repCount > 1 then
      -- Found direction repitition. Calculate dash path.
      local exits = getRoomExits(speedWalkPath[index+(repCount-1)])
      local pname = ""
      for word in speedWalkDir[index]:gmatch("%w") do pname = pname .. (dRef[word] or word) end
      if not exits[pname] or dashExaust then
        -- Final room in this direction does not continue, dash!
        table.insert(currentPath,string.format("%s %s",dashtype,speedWalkDir[index]))
        currentIds[#currentIds+1] = speedWalkPath[index+repCount-1]
      else
        -- Final room in this direction continues onwards, don't dash
        for i = 1,repCount do
          table.insert(currentPath,speedWalkDir[index])
          currentIds[#currentIds+1] = speedWalkPath[index]
        end
      end
      index = index + repCount
    else
      -- No repetition, just add the direction.
      table.insert(currentPath,speedWalkDir[index])
      currentIds[#currentIds+1] = speedWalkPath[index]
      index = index + 1
    end
  end

  speedWalkDir = currentPath
  speedWalkPath = currentIds
  return true
end

malaphus
Posts: 9
Joined: Mon Feb 01, 2010 11:47 pm

Re: IRE Mapper Script - Dashing Problem

Post by malaphus » Mon Mar 26, 2012 10:31 am

Fixed. Change:
Code: [show] | [select all] lua
for i = 1,repCount do
  table.insert(currentPath,speedWalkDir[index])
  currentIds[#currentIds+1] = speedWalkPath[index]
end
To:
Code: [show] | [select all] lua
for i = 1,repCount do
  table.insert(currentPath,speedWalkDir[index])
  currentIds[#currentIds+1] = speedWalkPath[index+i-1]
end
(adding "+i-1" to the currentIds line)

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: IRE Mapper Script - Dashing Problem

Post by tsuujin » Mon Mar 26, 2012 4:30 pm

If that ends up being a problem, I wrote an alternative version of the script for my own system that you can use as a reference:
Code: [show] | [select all] lua
--[[ Speedwalking Module ]]--

require "messages"

module("bsd.map.speedwalk",package.seeall)

-- Public variables
walking = false
lastDir = false
dashing = false
-- Private variables
local currentPath = {}
local currentRoom = nil
local walkIndex = nil
local dRef = {["n"] = "north", ["e"] = "east", ["s"] = "south", ["w"] = "west"}

function fixPath(rFrom,rTo)
	currentPath = {}
	local dRef = {["n"] = "north", ["e"] = "east", ["s"] = "south", ["w"] = "west"}
	if not getPath(rFrom,rTo) then msg.print("failed") return false end

	-- Logic: Look for a direction repeated at least two times.
	-- count the number of times it repeats, then look that many rooms ahead.
	-- if that room also contains the direction we're headed, just travel that many directions.
	-- otherwise, dash.

	local repCount = 1
	local index = 1
	local dashExaust = false
	while speedWalkDir[index] do
		dashExaust = false
		repCount = 1
		while speedWalkDir[index+repCount] == speedWalkDir[index] do
			repCount = repCount + 1
			if repCount == 11 then
				dashExaust = true
				break
			end
		end
		if repCount > 1 and dashing then
			-- Found direction repitition. Calculate dash path.
			local exits = getRoomExits(speedWalkPath[index+(repCount-1)])
			local pname = ""
			for word in speedWalkDir[index]:gmatch("%w") do pname = pname .. (dRef[word] or word) end
			if not exits[pname] or dashExaust then
				-- Final room in this direction does not continue, dash!
				table.insert(currentPath,{
					string.format("dash %s",speedWalkDir[index]),
					speedWalkPath[index+(repCount-1)]
				})
			else
				-- Final room in this direction continues onwards, don't dash
				for i = 1,repCount do
					table.insert(currentPath,{
						speedWalkDir[index],
						speedWalkPath[index+(i-1)]
					})
				end
			end
			index = index + repCount
		else
			-- No repetition, just add the direction.
			table.insert(currentPath,{
				speedWalkDir[index],
				speedWalkPath[index]
			})
		index = index + 1
		end
	end
	return true
end

function walk(room)
	if type(room) == "string" then
		local roomnum = bsd.map.waypoints.getRoomNumber(room)
		if not roomnum then
			msg.print(string.format("<yellow>Speedwalk: <white>No waypoint defined for <SpringGreen>%s",room))
			return false 
		end
		room = roomnum
	end
	if not fixPath(gmcp.Room.Info.num,room) then return false end
	-- Good to go. Start walking.
	walking = true
	send(currentPath[1][1])
	lastDir = currentPath[1][1]
	table.remove(currentPath,1)
end

function continue(event,args)
	if gmcp.Room.Info.num == currentRoom then return end
	currentRoom = gmcp.Room.Info.num
	if not currentPath[1] then
		walking = false
		msg.print("Speedwalking <SpringGreen>complete<white>!")
		return
	end
	msg.print(string.format("Moving %s",currentPath[1][1]))
	send(currentPath[1][1])
	lastDir = currentPath[1][1]
	table.remove(currentPath,1)
end

function stop()
	currentPath = {}
end

User avatar
Vadi
Posts: 4733
Joined: Sat Mar 14, 2009 3:13 pm

Re: IRE Mapper Script - Dashing Problem

Post by Vadi » Tue Mar 27, 2012 1:30 am

Thanks! The fix is in the latest update of the mapper script that's now available.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests