Package transientlibs.objects.misc

Source Code of transientlibs.objects.misc.GenericTask

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.objects.misc;

import transientlibs.objects.creatures.items.Item;
import transientlibs.bindedobjects.core.datasets.Action;
import transientlibs.bindedobjects.core.Maps;
import transientlibs.processors.misc.Detonator;
import transientlibs.maps.implementation.TilelessMap;
import transientlibs.maps.entities.Landmark;

import transientlibs.maps.utils.pathfinding.PathFinder;
import transientlibs.maps.tiles.Tile;
import transientlibs.maps.units.Unit;
import transientlibs.maps.implementation.BasicMap;
import transientlibs.objects.primitives.Coords;
import transientlibs.objects.primitives.Int;

/**
*
* @author kibertoad
*/
public class GenericTask {

    public int ID;
    public Tile onTile;
    public Action action;
    public Coords targetCoords = new Coords();
    public Landmark targetLandmark = null;
    public Coords movementCoords = new Coords();
    public Unit assignedMinion;
    public Int progressPoints = new Int(0);
    public Int progressPointsNeeded = new Int(100);

    public Item targetItem = null; //e. g. what kind of goods to haul   
   
    public void killTask() {
    }

    public void finishTask() {
        Detonator.INSTANCE.activeLandmark = targetLandmark;
    }


public void performTask (int taskPoints) {
    progressPoints.value +=  taskPoints;
   
    //Log.info("Task performed: "+progressPoints.value+"/"+progressPointsNeeded.value);
   
    if (progressPoints.value >= progressPointsNeeded.value) {finishTask();}
}

public void calculateMovementCoords (Coords fromCoords, TilelessMap fromMap) {

        PathFinder pathfinder = new PathFinder(fromCoords, fromMap);

        Coords adjustedCoords;

        int counter;
        int setX;
        int setY;
        int bestResult = 999999999;
        int bestDirection = -1;

        BasicMap onMap = Maps.currentMap;

        for (counter = 1; counter < 10; counter++) {

        adjustedCoords = targetCoords.returnAdjustedCoords(counter);
        setX = adjustedCoords.getIntX();
        setY = adjustedCoords.getIntY();

        onMap.pathfindingGoalX = setX;
        onMap.pathfindingGoalY = setY;

        pathfinder.goalX = setX;
        pathfinder.goalY = setY;

        pathfinder.updatePath();

        if (pathfinder.path != null) {
            if (pathfinder.path.getLength() < bestResult) {
                bestResult = pathfinder.path.getLength();
                bestDirection = counter;
            }

            //Log.info(counter+" is a viable direction.");
        }

        //counter++;
        }

        if (bestDirection != -1) {

            adjustedCoords = targetCoords.returnAdjustedCoords(bestDirection);

            movementCoords.x = adjustedCoords.x;
            movementCoords.y = adjustedCoords.y;

        } else {
            movementCoords.x = targetCoords.x;
            movementCoords.y = targetCoords.y;
        }

        //Log.info("Best path: "+bestDirection+", cost: "+bestResult);


    }

    public void bindValues(String prefix) {

        Detonator.INSTANCE.activeTask = this;

        Detonator.INSTANCE.setBindedValue("progress", progressPoints);
        Detonator.INSTANCE.setBindedValue("progressneeded", progressPointsNeeded);
    }

    public Landmark getLandmark() {
        return targetLandmark;
    }
}
TOP

Related Classes of transientlibs.objects.misc.GenericTask

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.