1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

PathingService skeleton

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-27 13:46:53 -03:00
parent faec07b8d5
commit 537b3968a9
10 changed files with 350 additions and 12 deletions

View File

@@ -22,8 +22,8 @@ import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.map.pathing.PathingService;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.service.game.pathing.PathingService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldIDService;

View File

@@ -35,10 +35,10 @@ import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.character.CharacterServiceImpl;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.chat.SimpleChatService;
import com.l2jserver.service.game.map.pathing.MapperPathingService;
import com.l2jserver.service.game.map.pathing.PathingService;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.service.game.npc.NPCServiceImpl;
import com.l2jserver.service.game.pathing.MapperPathingService;
import com.l2jserver.service.game.pathing.PathingService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
import com.l2jserver.service.game.spawn.SpawnService;

View File

@@ -0,0 +1,26 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map;
import com.l2jserver.service.AbstractService;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class GeoDataMapService extends AbstractService implements MapService {
}

View File

@@ -14,15 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.pathing;
package com.l2jserver.service.game.map;
import com.l2jserver.service.Service;
/**
* This service handles the pathing.
* This service provides information about the world map
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface PathingService extends Service {
public interface MapService extends Service {
}

View File

@@ -0,0 +1,48 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map;
import com.l2jserver.util.geometry.Point;
/**
* Tiles are 2D only
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Tile {
private final Point point;
private final byte flags;
public Tile(Point point, byte flags) {
this.point = point;
this.flags = flags;
}
/**
* @return the point
*/
public Point getPoint() {
return point;
}
/**
* @return the flags
*/
public byte getFlags() {
return flags;
}
}

View File

@@ -0,0 +1,41 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map.pathing;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.util.geometry.Point3D;
/**
* This {@link PathingService} implementation uses the A* algorithm to determine
* the best path possible.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends({ CharacterService.class, WorldService.class })
public class AStarPathingService extends AbstractService implements
PathingService {
@Override
public Path findPath(PositionableObject object, Point3D point) {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -0,0 +1,84 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map.pathing;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.geometry.Point3D;
/**
* Base {@link Path} for implementations
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class AbstractPath implements Path {
/**
* The source point
*/
protected final Point3D source;
/**
* The list of all points
*/
protected final List<Point3D> points = CollectionFactory.newList();
/**
* Creates a new instance
*
* @param source
* the source point
* @param points
* all pathing points
*/
public AbstractPath(Point3D source, Point3D... points) {
this.source = source;
Collections.addAll(this.points, points);
}
@Override
public double getDistance() {
int distance = 0;
Point3D last = source;
for (final Point3D point : points) {
distance += point.getDistance(last);
last = point;
}
return distance;
}
@Override
public Point3D getSource() {
return source;
}
@Override
public Point3D getTarget() {
return points.get(points.size() - 1);
}
@Override
public int getPointCount() {
return points.size();
}
@Override
public Iterator<Point3D> iterator() {
return points.iterator();
}
}

View File

@@ -14,13 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.pathing;
package com.l2jserver.service.game.map.pathing;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Iterator;
import javolution.io.Struct;
@@ -28,6 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.character.event.CharacterMoveEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
@@ -88,8 +90,9 @@ public class MapperPathingService extends AbstractService implements
@Override
protected void doStart() throws ServiceStartException {
try {
this.channel = new FileOutputStream(file).getChannel();
} catch (FileNotFoundException e) {
this.channel = new RandomAccessFile(file, "rw").getChannel();
this.channel.position(file.length());
} catch (IOException e) {
throw new ServiceStartException(
"Could not open pathing database file", e);
}
@@ -111,6 +114,11 @@ public class MapperPathingService extends AbstractService implements
});
}
@Override
public Path findPath(PositionableObject object, Point3D point) {
return new VoidPath(object.getPoint(), point);
}
@Override
protected void doStop() throws ServiceStopException {
try {
@@ -142,4 +150,44 @@ public class MapperPathingService extends AbstractService implements
return struct;
}
}
/**
* A pseudo-path. It will always trace the path in straight line.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
private class VoidPath implements Path {
private final Point3D source;
private final Point3D target;
public VoidPath(Point3D source, Point3D target) {
this.source = source;
this.target = target;
}
@Override
public Iterator<Point3D> iterator() {
return Arrays.asList(target).iterator();
}
@Override
public double getDistance() {
return source.getDistance(target);
}
@Override
public Point3D getSource() {
return source;
}
@Override
public Point3D getTarget() {
return target;
}
@Override
public int getPointCount() {
return 1;
}
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map.pathing;
import com.l2jserver.util.geometry.Point3D;
/**
* This interface represents the path an given object needs to do in order to
* avoid the obstacles in from of it.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Path extends Iterable<Point3D> {
/**
* @return the starting point
*/
Point3D getSource();
/**
* @return the last point
*/
Point3D getTarget();
/**
* @return the amount of points in this path
*/
int getPointCount();
/**
* Calculates the path real distance. This is actually the sum of distance
* of all nodes.
*
* @return the distance
*/
double getDistance();
}

View File

@@ -0,0 +1,41 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.map.pathing;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.service.Service;
import com.l2jserver.util.geometry.Point3D;
/**
* This service will try to find the best path to move to an given location.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface PathingService extends Service {
/**
* Tries to find a path for <tt>object</tt> move to <tt>point</tt>. If the
* algorithm could't find any viable path, <tt>null</tt> <b>must</b> be
* returned.
*
* @param object
* the object moving to <tt>point</tt>
* @param point
* the destination point
* @return the {@link Path}
*/
Path findPath(PositionableObject object, Point3D point);
}