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

View file

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