Scripts:Check walls at a distance

From OHRRPGCE-Wiki
Jump to navigation Jump to search

The commands check hero wall and check NPC wall can be used to check if a wall is blocking a hero or an NPC, but only on their current tile. If you want to check for walls a certain distance away from a hero or NPC, you can use a set of scripts like this:

script, check distant hero wall, who, direction, distance=0, begin
  exit returning(check wall relative to tile(hero x(who), hero y(who), direction, distance))
end

script, check distant NPC wall, who, direction, distance=0, begin
  exit returning(check wall relative to tile(npc x(who), npc y(who), direction, distance))
end

script, check wall relative to tile, x, y, direction, distance, begin
  switch(direction) do(
    case(north) do(y -= distance)
    case(south) do(y += distance)
    case(west) do(x -= distance)
    case(east) do(x += distance)
  )
  exit returning(check wall at spot(x, y, direction))
end

script, check wall at spot, x, y, direction, begin
  variable(tile1, tile2)
  tile1 := read pass block(x, y)
  switch(direction) do(
    case(north) do(
      tile2 := read pass block(x, y -- 1)
      if (tile1 ,and, northwall) then(exit returning(true))
      if (tile2 ,and, southwall) then(exit returning(true))
    )
    case(south) do(
      tile2 := read pass block(x, y + 1)
      if (tile1 ,and, southwall) then(exit returning(true))
      if (tile2 ,and, northwall) then(exit returning(true))
    )
    case(west) do(
      tile2 := read pass block(x -- 1, y)
      if (tile1 ,and, westwall) then(exit returning(true))
      if (tile2 ,and, eastwall) then(exit returning(true))
    )
    case(east) do(
      tile2 := read pass block(x + 1, y)
      if (tile1 ,and, eastwall) then(exit returning(true))
      if (tile2 ,and, westwall) then(exit returning(true))
    )
  )
  exit returning(false)
end

Be aware that these scripts are not smart enough to wrap around the edges of a wrapping map.