Android Open Source - acceptableLosses Path Finder System






From Project

Back to project page acceptableLosses.

License

The source code is released under:

MIT License

If you think the Android project acceptableLosses listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package acceptableLosses.systems;
//w w w. java 2s  .co m

import acceptableLosses.components.Destination;
import acceptableLosses.components.Path;
import acceptableLosses.components.Position;
import acceptableLosses.map.Region;
import acceptableLosses.pathing.FastNonOptimalHeuristic;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
import com.stewsters.util.pathing.threeDimention.pathfinder.AStarPathFinder3d;
import com.stewsters.util.pathing.threeDimention.pathfinder.PathFinder3d;
import com.stewsters.util.pathing.threeDimention.shared.FullPath3d;
import com.stewsters.util.pathing.threeDimention.shared.Mover3d;
import com.stewsters.util.pathing.threeDimention.shared.PathNode3d;

public class PathFinderSystem extends EntityProcessingSystem {

    @Wire
    ComponentMapper<Position> positionComponentMapper;

    @Wire
    ComponentMapper<Destination> destinationComponentMapper;

    private PathFinder3d pathFinder;

    private Region region;

    public PathFinderSystem(Region region) {
        super(Aspect.getAspectForAll(Destination.class, Position.class));
        pathFinder = new AStarPathFinder3d(region, region.xSize * region.ySize, false, new FastNonOptimalHeuristic());

        this.region = region;
    }

    @Override
    protected void process(Entity e) {

        Destination destination = destinationComponentMapper.get(e);
        Position position = positionComponentMapper.get(e);


        if (destination.dest.x == position.x &&
                destination.dest.y == position.y &&
                destination.dest.z == position.z) {

            Gdx.app.log("PathFinderSystem", "Already there.");

            e.edit().remove(Destination.class);
            return;
        }


        FullPath3d path = pathFinder.findPath(new Mover3d() {
            @Override
            public boolean canTraverse(PathNode3d pathNode) {
                return !region.tiles[pathNode.x][pathNode.y][pathNode.z].blocks;
            }
        }, position.x, position.y, position.z, destination.dest.x, destination.dest.y, destination.dest.z);


        if (path != null) {
            e.edit().create(Path.class).set(path);
            Gdx.app.log("PathFinderSystem", "Path created.");
        } else {
            Gdx.app.log("PathFinderSystem", "Could not path. Abandoned.");
        }
        e.edit().remove(Destination.class);


    }
}




Java Source Code List

acceptableLosses.AcceptableLossesGame.java
acceptableLosses.android.AndroidLauncher.java
acceptableLosses.assets.AssetLoader.java
acceptableLosses.assets.FurnitureType.java
acceptableLosses.assets.TileType.java
acceptableLosses.components.Appearance.java
acceptableLosses.components.Cargo.java
acceptableLosses.components.Citizen.java
acceptableLosses.components.Destination.java
acceptableLosses.components.Health.java
acceptableLosses.components.Path.java
acceptableLosses.components.Position.java
acceptableLosses.components.Resume.java
acceptableLosses.components.Sentience.java
acceptableLosses.components.Task.java
acceptableLosses.controls.GestureDetectorController.java
acceptableLosses.controls.InputManager.java
acceptableLosses.controls.ZoomInputProcessor.java
acceptableLosses.controls.commands.Command.java
acceptableLosses.controls.commands.TapCommand.java
acceptableLosses.desktop.DesktopLauncher.java
acceptableLosses.desktop.ImagePacker.java
acceptableLosses.map.AsteroidGenerator.java
acceptableLosses.map.Chunk.java
acceptableLosses.map.Furniture.java
acceptableLosses.map.MapTools.java
acceptableLosses.map.Region.java
acceptableLosses.map.Spawner.java
acceptableLosses.pathing.FastNonOptimalHeuristic.java
acceptableLosses.screens.GameScreen.java
acceptableLosses.screens.SplashScreen.java
acceptableLosses.systems.AiSystem.java
acceptableLosses.systems.AppearanceRenderSystem.java
acceptableLosses.systems.ElevationSystem.java
acceptableLosses.systems.FurnitureRenderSystem.java
acceptableLosses.systems.JobAssignerSystem.java
acceptableLosses.systems.MapRenderSystem.java
acceptableLosses.systems.MovementSystem.java
acceptableLosses.systems.PathFinderSystem.java
acceptableLosses.work.CivilianMover.java
acceptableLosses.work.jobs.DigJob.java
acceptableLosses.work.jobs.Job.java