com.massisframework.massis.ai.sposh.actions.GotoTarget Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of massis-ai-sposh Show documentation
Show all versions of massis-ai-sposh Show documentation
SPOSH High Level Controller
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.massisframework.massis.ai.sposh.actions;
import com.massisframework.massis.ai.sposh.SimulationContext;
import com.massisframework.massis.model.agents.LowLevelAgent;
import com.massisframework.massis.model.location.Location;
import com.massisframework.massis.model.managers.movement.ApproachCallback;
import com.massisframework.massis.pathfinding.straightedge.FindPathResult.PathFinderErrorReason;
import cz.cuni.amis.pogamut.sposh.executor.ActionResult;
import cz.cuni.amis.pogamut.sposh.executor.PrimitiveInfo;
/**
* Goes to assigned target
*
* @author rpax
*/
@PrimitiveInfo(name = "Go to target", description = "Goes to assigned target", tags = {
"parallel" })
public class GotoTarget extends SimulationAction {
public GotoTarget(SimulationContext ctx) {
super(ctx);
}
@Override
public void done() {
}
public ActionResult run() {
Location target = this.ctx.getTarget();
final ActionResult[] res = new ActionResult[1];
ApproachCallback approachCallBack = new ApproachCallback() {
@Override
public void onTargetReached(LowLevelAgent agent) {
res[0] = ActionResult.FINISHED;
}
@Override
public void onSucess(LowLevelAgent agent) {
res[0] = ActionResult.RUNNING_ONCE;
}
@Override
public void onPathFinderError(PathFinderErrorReason reason) {
res[0] = ActionResult.FINISHED;
ctx.setTarget(null);
}
};
this.ctx.getBot().approachTo(target, approachCallBack);
return res[0];
}
@Override
public void init() {
}
}