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();
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations