diff --git a/src/main/java/com/l2jserver/L2JGameServerMain.java b/src/main/java/com/l2jserver/L2JGameServerMain.java index 9c266fae3..35a69ce86 100644 --- a/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -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; diff --git a/src/main/java/com/l2jserver/service/ServiceModule.java b/src/main/java/com/l2jserver/service/ServiceModule.java index 19514c79d..ca507949b 100644 --- a/src/main/java/com/l2jserver/service/ServiceModule.java +++ b/src/main/java/com/l2jserver/service/ServiceModule.java @@ -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; diff --git a/src/main/java/com/l2jserver/service/game/map/GeoDataMapService.java b/src/main/java/com/l2jserver/service/game/map/GeoDataMapService.java new file mode 100644 index 000000000..4003c16b6 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/GeoDataMapService.java @@ -0,0 +1,26 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.service.game.map; + +import com.l2jserver.service.AbstractService; + +/** + * @author Rogiel + */ +public class GeoDataMapService extends AbstractService implements MapService { + +} diff --git a/src/main/java/com/l2jserver/service/game/pathing/PathingService.java b/src/main/java/com/l2jserver/service/game/map/MapService.java similarity index 84% rename from src/main/java/com/l2jserver/service/game/pathing/PathingService.java rename to src/main/java/com/l2jserver/service/game/map/MapService.java index 7717290f0..47ecd6b39 100644 --- a/src/main/java/com/l2jserver/service/game/pathing/PathingService.java +++ b/src/main/java/com/l2jserver/service/game/map/MapService.java @@ -14,15 +14,15 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -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 Rogiel */ -public interface PathingService extends Service { - +public interface MapService extends Service { + } diff --git a/src/main/java/com/l2jserver/service/game/map/Tile.java b/src/main/java/com/l2jserver/service/game/map/Tile.java new file mode 100644 index 000000000..9482db893 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/Tile.java @@ -0,0 +1,48 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.service.game.map; + +import com.l2jserver.util.geometry.Point; + +/** + * Tiles are 2D only + * + * @author Rogiel + */ +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; + } +} diff --git a/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java b/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java new file mode 100644 index 000000000..75c3c79ae --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/pathing/AStarPathingService.java @@ -0,0 +1,41 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +@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; + } + +} diff --git a/src/main/java/com/l2jserver/service/game/map/pathing/AbstractPath.java b/src/main/java/com/l2jserver/service/game/map/pathing/AbstractPath.java new file mode 100644 index 000000000..59dcade44 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/pathing/AbstractPath.java @@ -0,0 +1,84 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +public abstract class AbstractPath implements Path { + /** + * The source point + */ + protected final Point3D source; + /** + * The list of all points + */ + protected final List 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 iterator() { + return points.iterator(); + } +} diff --git a/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java b/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java similarity index 78% rename from src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java rename to src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java index c68b4708a..e007b1188 100644 --- a/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java +++ b/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java @@ -14,13 +14,14 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -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 Rogiel + */ + 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 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; + } + } } diff --git a/src/main/java/com/l2jserver/service/game/map/pathing/Path.java b/src/main/java/com/l2jserver/service/game/map/pathing/Path.java new file mode 100644 index 000000000..94d660562 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/pathing/Path.java @@ -0,0 +1,50 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +public interface Path extends Iterable { + /** + * @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(); +} diff --git a/src/main/java/com/l2jserver/service/game/map/pathing/PathingService.java b/src/main/java/com/l2jserver/service/game/map/pathing/PathingService.java new file mode 100644 index 000000000..d7df5303a --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/map/pathing/PathingService.java @@ -0,0 +1,41 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +public interface PathingService extends Service { + /** + * Tries to find a path for object move to point. If the + * algorithm could't find any viable path, null must be + * returned. + * + * @param object + * the object moving to point + * @param point + * the destination point + * @return the {@link Path} + */ + Path findPath(PositionableObject object, Point3D point); +}