Search in sources :

Example 26 with Base

use of spacesettlers.objects.Base 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();
    }
}
Also used : Position(spacesettlers.utilities.Position) AiCore(spacesettlers.objects.AiCore) Beacon(spacesettlers.objects.Beacon) Ship(spacesettlers.objects.Ship) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction) Base(spacesettlers.objects.Base) MoveToObjectAction(spacesettlers.actions.MoveToObjectAction)

Example 27 with Base

use of spacesettlers.objects.Base in project spacesettlers by amymcgovern.

the class AggressiveHeuristicAsteroidCollectorTeamClient method findNearestBase.

/**
 * Find the base for this team nearest to this ship
 *
 * @param space
 * @param ship
 * @return
 */
private Base findNearestBase(Toroidal2DPhysics space, Ship ship) {
    double minDistance = Double.MAX_VALUE;
    Base nearestBase = null;
    for (Base base : space.getBases()) {
        if (base.getTeamName().equalsIgnoreCase(ship.getTeamName())) {
            double dist = space.findShortestDistance(ship.getPosition(), base.getPosition());
            if (dist < minDistance) {
                minDistance = dist;
                nearestBase = base;
            }
        }
    }
    return nearestBase;
}
Also used : Base(spacesettlers.objects.Base)

Example 28 with Base

use of spacesettlers.objects.Base in project spacesettlers by amymcgovern.

the class CollisionHandler method missileCollision.

/**
 * Collide with a missile
 * @param object1
 * @param object2
 */
private void missileCollision(Missile missile, AbstractObject object2) {
    // get the ship that fired this
    Ship firingShip = missile.getFiringShip();
    firingShip.decrementWeaponCount();
    // did it hit a ship?
    if (object2.getClass() == Ship.class) {
        Ship ship = (Ship) object2;
        // only take damageInflicted if not shielded
        if (!ship.isShielded()) {
            double initialEnergy = ship.getEnergy();
            ship.updateEnergy(missile.getDamage());
            if (ship.getEnergy() <= 0) {
                // if you killed the ship, only count the final amount of damage needed to kill it
                firingShip.incrementDamageInflicted((int) initialEnergy);
                ship.incrementDamageReceived(-(int) initialEnergy);
            } else {
                // otherwise a missile is a fixed amount of damage
                firingShip.incrementDamageInflicted(-missile.getDamage());
                ship.incrementDamageReceived(missile.getDamage());
            }
            // it hit a ship
            firingShip.incrementHitsInflicted();
        }
        // if the bullet killed the ship, credit the ship that hit it
        if (ship.getEnergy() <= 0) {
            // System.out.println("ship " + firingShip.getTeamName() + " stealing resourcesAvailable " + shipMoney + " from " + ship.getTeamName() + ship.getId());
            // it killed a ship
            firingShip.incrementKillsInflicted();
            ship.incrementKillsReceived();
        }
    }
    // did it hit a base?
    if (object2.getClass() == Base.class) {
        Base base = (Base) object2;
        // only take damageInflicted if not shielded
        if (!base.isShielded()) {
            double initialEnergy = base.getEnergy();
            base.updateEnergy(missile.getDamage());
            if (base.getEnergy() <= 0) {
                // if the base is dead, you can only count the energy it had prior to being dead
                firingShip.incrementDamageInflicted((int) initialEnergy);
                base.incrementDamageReceived(-(int) initialEnergy);
            // System.out.println("Firing at a dead base - should give only " + (int) -initialEnergy + " in damage");
            } else {
                // otherwise the missles count constant
                firingShip.incrementDamageInflicted(-missile.getDamage());
                base.incrementDamageReceived(missile.getDamage());
            }
            // it hit a base
            firingShip.incrementHitsInflicted();
        }
    }
    // Handle a bullet hitting a bullet
    if (object2.getClass() == Missile.class) {
        object2.setAlive(false);
        Ship otherFiringShip = ((Missile) object2).getFiringShip();
        otherFiringShip.decrementWeaponCount();
    }
    // Did the missile hit an AiCore? If so, damage the AiCore.
    if (object2.getClass() == AiCore.class) {
        AiCore core = (AiCore) object2;
        core.updateEnergy(-missile.getDamage());
    }
    // make the missile die
    missile.setAlive(false);
}
Also used : Missile(spacesettlers.objects.weapons.Missile) AiCore(spacesettlers.objects.AiCore) Ship(spacesettlers.objects.Ship) Base(spacesettlers.objects.Base)

Example 29 with Base

use of spacesettlers.objects.Base in project spacesettlers by amymcgovern.

the class CollisionHandler method EMPCollision.

/**
 * Collide with a EMP
 * @param object1
 * @param object2
 */
private void EMPCollision(EMP emp, AbstractObject object2) {
    // get the ship that fired
    Ship firingShip = emp.getFiringShip();
    firingShip.decrementWeaponCount();
    if (object2.getClass() == Ship.class) {
        Ship ship = (Ship) object2;
        // only take a hit if not shielded
        if (!ship.isShielded()) {
            ship.updateEnergy(emp.getDamage());
            ship.incrementDamageReceived(emp.getDamage());
            ship.setFreezeCount(emp.getFreezeCount());
            // it hit a ship
            firingShip.incrementHitsInflicted();
        }
    }
    if (object2.getClass() == Base.class) {
        Base base = (Base) object2;
        // only take a hit if not shielded
        if (!base.isShielded()) {
            base.updateEnergy(emp.getDamage());
            base.incrementDamageReceived(emp.getDamage());
            base.setFreezeCount(emp.getFreezeCount());
            // it hit a base
            firingShip.incrementHitsInflicted();
        }
    }
    // Handle a emp hitting a emp (no damageInflicted but both weapons die)
    if (object2.getClass() == EMP.class) {
        object2.setAlive(false);
        Ship otherFiringShip = ((EMP) object2).getFiringShip();
        otherFiringShip.decrementWeaponCount();
    }
    // Did the EMP hit an AiCore? If so, destroy the AiCore.
    if (object2.getClass() == AiCore.class) {
        AiCore core = (AiCore) object2;
        // Kill the core!
        core.setAlive(false);
    }
    emp.setAlive(false);
}
Also used : AiCore(spacesettlers.objects.AiCore) EMP(spacesettlers.objects.weapons.EMP) Ship(spacesettlers.objects.Ship) Base(spacesettlers.objects.Base)

Example 30 with Base

use of spacesettlers.objects.Base in project spacesettlers by amymcgovern.

the class ObjectInfoPanel method updateData.

/**
 * Update the GUI for this step using the simulator data as needed
 * @param simulator
 */
public void updateData(SpaceSettlersSimulator simulator) {
    // do not update if there is no selected object
    if (this.selectedObject == null) {
        return;
    }
    String name = "";
    if (selectedObject.getClass() == Asteroid.class) {
        Asteroid asteroid = (Asteroid) selectedObject;
        if (asteroid.isMineable()) {
            name = "Mineable asteroid";
        } else {
            name = "Non-mineable asteroid";
        }
    } else if (selectedObject.getClass() == Base.class) {
        Base base = (Base) selectedObject;
        name = "Base for " + base.getTeamName();
    } else if (selectedObject.getClass() == Ship.class) {
        Ship ship = (Ship) selectedObject;
        name = "Ship for " + ship.getTeamName();
    } else if (selectedObject.getClass() == Beacon.class) {
        Beacon beacon = (Beacon) selectedObject;
        name = "Beacon";
    }
    objectName.setText(name);
    innerPanel.updateData(simulator);
    resourcesPanel.updateData(selectedObject);
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Beacon(spacesettlers.objects.Beacon) Ship(spacesettlers.objects.Ship) Base(spacesettlers.objects.Base)

Aggregations

Base (spacesettlers.objects.Base)30 Ship (spacesettlers.objects.Ship)19 UUID (java.util.UUID)11 AbstractAction (spacesettlers.actions.AbstractAction)11 DoNothingAction (spacesettlers.actions.DoNothingAction)11 Position (spacesettlers.utilities.Position)11 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)10 Beacon (spacesettlers.objects.Beacon)10 HashMap (java.util.HashMap)8 AbstractActionableObject (spacesettlers.objects.AbstractActionableObject)8 Asteroid (spacesettlers.objects.Asteroid)8 AiCore (spacesettlers.objects.AiCore)7 PurchaseTypes (spacesettlers.actions.PurchaseTypes)6 AbstractObject (spacesettlers.objects.AbstractObject)4 Flag (spacesettlers.objects.Flag)3 ResourcePile (spacesettlers.objects.resources.ResourcePile)2 LinkedHashSet (java.util.LinkedHashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1