use of spacesettlers.actions.MoveToObjectAction in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorTeamClient method getWeaponShipAction.
/**
* Gets the action for the weapons based ship
* @param space
* @param ship
* @return
*/
private AbstractAction getWeaponShipAction(Toroidal2DPhysics space, Ship ship) {
AbstractAction current = ship.getCurrentAction();
Position currentPosition = ship.getPosition();
// aim for a beacon if there isn't enough energy
if (ship.getEnergy() < 2000) {
Beacon beacon = pickNearestBeacon(space, ship);
AbstractAction newAction = null;
// if there is no beacon, then just skip a turn
if (beacon == null) {
newAction = new DoNothingAction();
} else {
newAction = new MoveToObjectAction(space, currentPosition, beacon);
}
aimingForBase.put(ship.getId(), false);
goingForCore.put(ship.getId(), false);
return newAction;
}
// if the ship has enough resourcesAvailable, take it back to base
if (ship.getResources().getTotal() > 500 || ship.getNumCores() > 0) {
Base base = findNearestBase(space, ship);
AbstractAction newAction = new MoveToObjectAction(space, currentPosition, base);
aimingForBase.put(ship.getId(), true);
goingForCore.put(ship.getId(), false);
return newAction;
}
// did we bounce off the base?
if (ship.getResources().getTotal() == 0 && ship.getEnergy() > 2000 && aimingForBase.containsKey(ship.getId()) && aimingForBase.get(ship.getId())) {
current = null;
goingForCore.put(ship.getId(), false);
aimingForBase.put(ship.getId(), false);
}
// if there is a nearby core, go get it
AiCore nearbyCore = pickNearestCore(space, ship, 100);
if (nearbyCore != null) {
Position newGoal = nearbyCore.getPosition();
AbstractAction newAction = new MoveToObjectAction(space, currentPosition, nearbyCore);
goingForCore.put(ship.getId(), true);
aimingForBase.put(ship.getId(), false);
return newAction;
}
// otherwise aim for the nearest enemy ship
if (current == null || current.isMovementFinished(space)) {
aimingForBase.put(ship.getId(), false);
goingForCore.put(ship.getId(), false);
Ship enemy = pickNearestEnemyShip(space, ship);
AbstractAction newAction = null;
if (enemy == null) {
// there is no enemy available so collect a beacon
Beacon beacon = pickNearestBeacon(space, ship);
// if there is no beacon, then just skip a turn
if (beacon == null) {
newAction = new DoNothingAction();
} else {
newAction = new MoveToObjectAction(space, currentPosition, beacon);
}
} else {
newAction = new MoveToObjectAction(space, currentPosition, enemy, enemy.getPosition().getTranslationalVelocity());
}
return newAction;
} else {
return ship.getCurrentAction();
}
}
Aggregations