Package com.l2jfrozen.gameserver.geo.pathfinding.cellnodes

Source Code of com.l2jfrozen.gameserver.geo.pathfinding.cellnodes.CellPathFinding

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jfrozen.gameserver.geo.pathfinding.cellnodes;

import com.l2jfrozen.gameserver.geo.GeoData;
import com.l2jfrozen.gameserver.geo.pathfinding.Node;
import com.l2jfrozen.gameserver.geo.pathfinding.PathFinding;
import com.l2jfrozen.gameserver.model.L2World;


public final class CellPathFinding extends PathFinding
{
  private static final class SingletonHolder {
    protected static final CellPathFinding INSTANCE = new CellPathFinding();
  }
 
  public static CellPathFinding getInstance()
  {
    return SingletonHolder.INSTANCE;
  }
 
  @Override
  public Node[] findPath(int x, int y, int z, int tx, int ty, int tz)
  {
    int gx = x - L2World.MAP_MIN_X >> 4;
    int gy = y - L2World.MAP_MIN_Y >> 4;
    if(!GeoData.getInstance().hasGeo(x, y))
      return null;
    short gz = GeoData.getInstance().getHeight(x, y, z);
    int gtx = tx - L2World.MAP_MIN_X >> 4;
    int gty = ty - L2World.MAP_MIN_Y >> 4;
    if(!GeoData.getInstance().hasGeo(tx, ty))
      return null;
    short gtz = GeoData.getInstance().getHeight(tx, ty, tz);
    Node start = readNode(gx, gy, gz);
    Node end = readNode(gtx, gty, gtz);
    return searchByClosest(start, end);
  }
 
  @Override
  public Node[] readNeighbors(Node n, int idx)
  {
    return GeoData.getInstance().getNeighbors(n);
  }

  //Private

  public Node readNode(int gx, int gy, short z)
  {
    return new CellNode(gx, gy, z, 0);
  }

  protected CellPathFinding()
  {
    //
  }
}
TOP

Related Classes of com.l2jfrozen.gameserver.geo.pathfinding.cellnodes.CellPathFinding

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-20639858-1', 'auto'); ga('send', 'pageview');