Android Open Source - acceptableLosses Job Assigner 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  ww.  j  a va2  s  .c  om*/
import acceptableLosses.components.*;
import acceptableLosses.map.Region;
import acceptableLosses.work.CivilianMover;
import acceptableLosses.work.jobs.Job;
import acceptableLosses.work.jobs.JobObjective;
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.math.Facing3d;
import com.stewsters.util.math.Point3i;
import com.stewsters.util.pathing.threeDimention.searcher.DjikstraSearcher3d;
import com.stewsters.util.pathing.threeDimention.shared.FullPath3d;
import com.stewsters.util.spatial.IntervalKDTree3d;

import java.util.HashSet;

/**
 * This doles out tasks
 */
public class JobAssignerSystem extends EntityProcessingSystem {

    IntervalKDTree3d jobs;
    private HashSet<Job> jobTemp;

    private final Region region;
    private final DjikstraSearcher3d searcher;

    @Wire
    ComponentMapper<Resume> resumeComponentMapper;
    @Wire
    ComponentMapper<Position> positionComponentMapper;

    public JobAssignerSystem(Region region) {
        super(Aspect.getAspectForAll(Resume.class, Sentience.class, Position.class));
        searcher = new DjikstraSearcher3d(region, 10000, false);
        this.region = region;

        //optimize this
        int size = Math.max(Math.max(region.xSize, region.ySize), region.zSize);

        jobs = new IntervalKDTree3d((size / 2) + 1, 10);
    }

    //add
    public void addJob(Job job) {
        float radius = job.getWorkDistance() / 2f;
        Point3i e = job.getStartPos();
        jobs.put(e.x - radius, e.y - radius, e.z - radius, e.x + radius, e.y + radius, e.z + radius, e);
    }

    //remove

    public void remove(Job e) {
        jobs.remove(e);
    }


    public HashSet<Entity> getEntitiesAtLocation(int x, int y, int z) {
        jobTemp.clear();
        return jobs.getValues(x - 0.5, y - 0.5, z - 0.5, x + 0.5, y + 0.5, z + 0.5, jobTemp);
    }

    public HashSet<Entity> getEntitiesBetween(int lowX, int lowY, int lowZ, int highX, int highY, int highZ) {
        jobTemp.clear();
        return jobs.getValues(lowX - 0.5, lowY - 0.5, lowZ - 0.5, highX + 0.5, highY + 0.5, highZ + 0.5, jobTemp);
    }

    @Override
    protected void process(Entity e) {

        Resume resume = resumeComponentMapper.get(e);
        Position position = positionComponentMapper.get(e);


        //find any local jobs.

        // sort by distance, do job




//
//                FullPath3d fullPath3d = searcher.search(
//                new CivilianMover(region),
//                position.x, position.y, position.z,
//                new JobObjective(region, resume)
//        );


//        if (fullPath3d != null) {
//            // we are near a potential job, find it.
//
//            FullPath3d.Step step = fullPath3d.getStep(fullPath3d.getLength() - 1);
//            Job job = null;
//
//            for (Facing3d facing : Facing3d.values()) {
//                Job prospectiveJob = region.getJobAt(step.getX() + facing.x, step.getY() + facing.y, step.getZ() + facing.z);
//
//                if (prospectiveJob != null && prospectiveJob.satisfiedBy(resume) && prospectiveJob.getAssignee() == 0) {
//                    job = prospectiveJob;
//                    break;
//                }
//
//            }
//
//            if (job != null) {
//                // TODO: Add Task to player containing the job
//                job.setAssignee(e.getId());
//                e.edit().create(Task.class).set(job);
//                e.edit().create(Path.class).set(fullPath3d);
//            } else {
//                Gdx.app.log(this.getClass().getName(), "There is a path, but no jerbs");
//            }
//
//        } else {
//            Gdx.app.log(this.getClass().getName(), "There is no path to a job");
//        }
//        e.edit().remove(Resume.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