use of megamek.common.Entity in project megameklab by MegaMek.
the class UnitPrintQueueDialog method refresh.
private void refresh() {
unitList.removeAll();
Vector<String> unitNameList = new Vector<String>();
for (Entity ent : units) {
unitNameList.add(String.format("%1$s %2$s", ent.getChassis(), ent.getModel()).trim());
}
unitList.setListData(unitNameList);
unitList.repaint();
}
use of megamek.common.Entity in project spoon by INRIA.
the class TestBot method calculateMoveTurn.
public MovePath calculateMoveTurn() {
long enter = System.currentTimeMillis();
int initiative = 0;
MoveOption min = null;
System.out.println("beginning movement calculations...");
// first check and that someone else has moved so we don't replan
Object[] enemy_array = this.getEnemyEntities().toArray();
for (int j = 0; j < enemy_array.length; j++) {
if (!((Entity) enemy_array[j]).isSelectableThisTurn()) {
initiative++;
}
}
// if nobody's moved and we have a valid move waiting, use that
if (initiative == enemies_moved && old_moves != null) {
min = this.old_moves.getResult();
if (min == null || !min.isMoveLegal() || (min.isPhysical && centities.get(min.getPhysicalTargetId()).isPhysicalTarget)) {
this.old_moves = null;
System.out.println("recalculating moves since the old move was invalid");
return calculateMoveTurn();
}
} else {
enemies_moved = initiative;
Vector possible = new Vector();
Enumeration e = game.getEntities();
while (e.hasMoreElements()) {
Entity entity = (Entity) e.nextElement();
// ignore loaded units
if (entity.getPosition() == null) {
continue;
}
CEntity cen = centities.get(entity);
cen.refresh();
firstPass(cen);
}
Iterator i = this.getEntitiesOwned().iterator();
boolean short_circuit = false;
while (i.hasNext() && !short_circuit) {
Entity entity = (Entity) i.next();
// (not really necessary unless bot manages to load units)
if (entity.getPosition() == null) {
continue;
}
// if we can't move this entity right now, ignore it
if (!game.getTurn().isValidEntity(entity, game)) {
continue;
}
CEntity cen = centities.get(entity);
System.out.println("Contemplating movement of " + entity.getShortName() + " " + entity.getId());
MoveOption[] result = calculateMove(entity);
if (game.getOptions().booleanOption("skip_ineligable_movement") && cen.getEntity().isImmobile()) {
cen.moved = true;
} else if (!cen.moved) {
if (result.length < 6) {
min = result.length > 0 ? (MoveOption) result[0] : null;
short_circuit = true;
}
possible.add(result);
}
}
// and only do the below when there are 2 or mechs left to move
if (!short_circuit) {
if (this.getEntitiesOwned().size() > 1) {
GALance lance = new GALance(this, possible, 50, 80);
lance.evolve();
min = lance.getResult();
this.old_moves = lance;
} else if (((MoveOption[]) possible.elementAt(0)) != null && ((MoveOption[]) possible.elementAt(0)).length > 0) {
min = ((MoveOption[]) possible.elementAt(0))[0];
}
}
}
if (min == null) {
min = new MoveOption(game, centities.get(getFirstEntityNum()));
}
for (int d = 0; d < enemy_array.length; d++) {
Entity en = (Entity) enemy_array[d];
// ignore loaded units
if (en.getPosition() == null) {
continue;
}
CEntity enemy = centities.get(en);
int enemy_hit_arc = CEntity.getThreatHitArc(enemy.current.getFinalCoords(), enemy.current.getFinalFacing(), min.getFinalCoords());
MoveOption.DamageInfo di = (MoveOption.DamageInfo) min.damageInfos.get(enemy);
if (di != null) {
enemy.expected_damage[enemy_hit_arc] += di.min_damage;
}
if (enemy.expected_damage[enemy_hit_arc] > 0) {
enemy.hasTakenDamage = true;
}
}
if (min.isPhysical) {
centities.get(min.getPhysicalTargetId()).isPhysicalTarget = true;
}
System.out.println(min);
min.getCEntity().current = min;
min.getCEntity().last = min;
this.my_mechs_moved++;
min.getCEntity().moved = true;
long exit = System.currentTimeMillis();
System.out.println("move turn took " + (exit - enter) + " ms");
return min;
}
use of megamek.common.Entity in project spoon by INRIA.
the class TestBot method bestAttack.
public GAAttack bestAttack(MoveOption es, CEntity target, int search_level) {
Entity en = es.getEntity();
int[] attacks = new int[3];
Vector front = new Vector();
Vector left = new Vector();
Vector right = new Vector();
GAAttack result = null;
int o_facing = en.getFacing();
for (Enumeration i = en.getWeapons(); i.hasMoreElements(); ) {
Mounted mw = (Mounted) i.nextElement();
Vector c = this.calculateWeaponAttacks(en, mw, true);
if (c.size() > 0) {
front.add(c);
attacks[0] = Math.max(attacks[0], c.size());
}
if (!es.getFinalProne() && en.canChangeSecondaryFacing()) {
en.setSecondaryFacing((o_facing + 5) % 6);
c = this.calculateWeaponAttacks(en, mw, true);
if (c.size() > 0) {
left.add(c);
attacks[1] = Math.max(attacks[1], c.size());
}
en.setSecondaryFacing((o_facing + 1) % 6);
c = this.calculateWeaponAttacks(en, mw, true);
if (c.size() > 0) {
right.add(c);
attacks[2] = Math.max(attacks[2], c.size());
}
} else {
attacks[1] = 0;
attacks[2] = 0;
}
en.setSecondaryFacing(o_facing);
}
Vector arcs = new Vector();
arcs.add(front);
if (!es.getFinalProne() && en.canChangeSecondaryFacing()) {
arcs.add(left);
arcs.add(right);
}
for (int i = 0; i < arcs.size(); i++) {
Vector v = (Vector) arcs.elementAt(i);
if (v.size() > 0) {
GAAttack test = new GAAttack(this, centities.get(en), v, Math.max((v.size() + attacks[i]) * search_level, 20 * search_level), 30 * search_level, en.isEnemyOf((Entity) getEntitiesOwned().get(0)));
test.setFiringArc(i);
test.evolve();
if (target != null) {
if (result == null || test.getDamageUtility(target) > result.getDamageUtility(target)) {
result = test;
}
} else if (result == null || test.getFittestChromosomesFitness() > result.getFittestChromosomesFitness()) {
result = test;
}
}
}
return result;
}
Aggregations