allow robots to continue working if there is no available recharging station

This commit is contained in:
Hea3veN 2015-04-04 12:06:56 -03:00
parent 9ee5947397
commit 7e5270685e
2 changed files with 20 additions and 1 deletions

View file

@ -14,9 +14,11 @@ import buildcraft.api.robots.EntityRobotBase;
public class AIRobotMain extends AIRobot {
private AIRobot overridingAI;
private int rechargeCooldown;
public AIRobotMain(EntityRobotBase iRobot) {
super(iRobot);
rechargeCooldown = 0;
}
@Override
@ -32,7 +34,9 @@ public class AIRobotMain extends AIRobot {
}
} else if (robot.getEnergy() < EntityRobotBase.SAFETY_ENERGY) {
if (!(ai instanceof AIRobotRecharge) && !(ai instanceof AIRobotShutdown)) {
startDelegateAI(new AIRobotRecharge(robot));
if (rechargeCooldown-- == 0) {
startDelegateAI(new AIRobotRecharge(robot));
}
}
} else if (overridingAI != null && ai != overridingAI) {
startDelegateAI(overridingAI);
@ -50,6 +54,11 @@ public class AIRobotMain extends AIRobot {
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotRecharge) {
if (!ai.success()) {
rechargeCooldown = 120;
}
}
if (ai == overridingAI) {
overridingAI = null;
}

View file

@ -16,8 +16,11 @@ import buildcraft.robotics.IStationFilter;
public class AIRobotRecharge extends AIRobot {
private boolean success;
public AIRobotRecharge(EntityRobotBase iRobot) {
super(iRobot);
success = false;
}
@Override
@ -53,7 +56,14 @@ public class AIRobotRecharge extends AIRobot {
if (!ai.success()) {
setSuccess(false);
terminate();
} else {
success = true;
}
}
}
@Override
public boolean success() {
return success;
}
}