The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Tsunokiette on October 01, 2006, 09:18:24 PM

Title: Path Finder v 0.4
Post by: Tsunokiette on October 01, 2006, 09:18:24 PM
Another In Progress Script.

Won't be the best in the world, but will use a method a little different than the others.

Code: [Select]
def find_path(event_id, tile_x, tile_y)
   path = Path.new(event_id)
   path.find(tile_x,tile_y)
end

class Path

   def initialize(event_id)
      @map = $game_map
      if event_id == 9999
         @event = $game_player
      else
         @event = @map.events[event_id]
      end
      @open_tiles = set
   end

   def find(tile_x,tile_y)
      @paths = []
      if @event.lock?
         return p 'Error :  Event Position Locked Cannot Move'
      elsif !@open_tiles.include?([@event.x,@event.y])
         return p 'Error :  Movement Not Allowed From Current Possition'
      end
      @x = @event.x.deep_clone
      @y = @event.y.deep_clone
      border = [[@x, @y - 1], [@x + 1, @y], [@x, @y + 1], [@x - 1, @y]]
      total_possible_paths = 0
      for tile in border
         total_possible_paths += 1 if @open_tiles.include?(tile)
      end
      for i in 0..(total_possible_paths)
         @paths[i] = Possible_Path.new
         # Code to Map Path Goes Here
      end
      distances = []
      for i in 0..(@paths.size)
         distances[i] = @paths[i].distance
      end
      @best_path =  @paths.find{ |path| path.distance == distances.min }
   end

   def move
      # Code to move Goes Here
   end

   def set
      temp = []
      for x in 0..(@map.width / 32)
         for y in 0..(@map.height / 32)
            temp.push([x,y]) if @map.passable?(x,y,0)
        end
      end
      return temp
   end

end

class Possible_Path
   # Code for Storing Path Information Goes Here
end

class Object
   def deep_clone
      file = File.open('cloning.txt', "wb")
      Marshal.dump(self,file)
      file.close
      file = File.open('cloning.txt', "rb")
      data = Marshal.load(file)
      file.close
      return data
   end
end
Title: Re: Path Finder v 0.4
Post by: Arrow on October 01, 2006, 09:21:02 PM
...So what does it do, exactly?
Title: Re: Path Finder v 0.4
Post by: Tsunokiette on October 01, 2006, 09:21:44 PM
Eventually it will test all possible paths and find the shortest route, and move the event/player to the chosen position.

EDIT : @programmers - Slight rewriting needed for the add_sub definition, I'll get it done, it's just notepad is hard to program with.

EDIT 2 : As a matter of fact, I'm going to have to rewrite the Possible_Path class all together. -_-
Title: Re: Path Finder v 0.4
Post by: Arrow on October 01, 2006, 09:22:36 PM
Oh, sweet! I can think of all kinds of uses for this...