Skip to content

Commit

Permalink
Merge pull request #4094 from SJuliez/ForceAssignable
Browse files Browse the repository at this point in the history
Facilitating other game types: disconnecting Force and Entity
  • Loading branch information
SJuliez authored Jan 15, 2023
2 parents 111c9b8 + a799bb8 commit 7736c49
Show file tree
Hide file tree
Showing 93 changed files with 1,122 additions and 744 deletions.
14 changes: 6 additions & 8 deletions megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,6 @@ protected boolean keepGameLog() {
return PreferenceManager.getClientPreferences().keepGameLog();
}

/**
* Return an enumeration of the players in the game
*/
public Enumeration<Player> getPlayers() {
return game.getPlayers();
}

public Entity getEntity(int id) {
return game.getEntity(id);
}
Expand Down Expand Up @@ -1013,7 +1006,12 @@ protected void receiveForcesDelete(Packet c) {
Set<Force> delForces = new HashSet<>();
Set<Entity> delEntities = new HashSet<>();
forceIds.stream().map(forces::getForce).forEach(delForces::add);
delForces.stream().map(forces::getFullEntities).forEach(delEntities::addAll);
for (Force delForce : delForces) {
forces.getFullEntities(delForce).stream()
.filter(e -> e instanceof Entity)
.map(e -> (Entity) e)
.forEach(delEntities::add);
}

forces.deleteForces(delForces);

Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/bot/MoveOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int getPhysicalTargetId() {
if (target == null) {
return -1;
}
return target.getTargetId();
return target.getId();
}

@Override
Expand Down
26 changes: 13 additions & 13 deletions megamek/src/megamek/client/bot/PhysicalOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,57 +82,57 @@ public PhysicalOption(Entity attacker, Targetable target, double dmg,
public AbstractAttackAction toAction() {
switch (type) {
case PUNCH_LEFT:
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getTargetId(),
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getId(),
PunchAttackAction.LEFT);
case PUNCH_RIGHT:
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getTargetId(),
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getId(),
PunchAttackAction.RIGHT);
case PUNCH_BOTH:
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getTargetId(),
return new PunchAttackAction(attacker.getId(), target.getTargetType(), target.getId(),
PunchAttackAction.BOTH);
case KICK_LEFT:
return new KickAttackAction(attacker.getId(), target.getTargetType(), target.getTargetId(),
return new KickAttackAction(attacker.getId(), target.getTargetType(), target.getId(),
KickAttackAction.LEFT);
case KICK_RIGHT:
return new KickAttackAction(attacker.getId(), target.getTargetType(), target.getTargetId(),
return new KickAttackAction(attacker.getId(), target.getTargetType(), target.getId(),
KickAttackAction.RIGHT);
case USE_CLUB:
if (club != null) {
return new ClubAttackAction(attacker.getId(), target.getTargetType(), target
.getTargetId(), club, ToHitData.HIT_NORMAL, false);
.getId(), club, ToHitData.HIT_NORMAL, false);
}
return null;
case PUSH_ATTACK:
return new PushAttackAction(attacker.getId(), target.getTargetId(),
return new PushAttackAction(attacker.getId(), target.getId(),
target.getPosition());
case TRIP_ATTACK:
return null; // Trip attack not implemented yet
case BRUSH_LEFT:
if (target == null) {
return new BrushOffAttackAction(attacker.getId(), i_target
.getTargetType(), i_target.getTargetId(),
.getTargetType(), i_target.getId(),
BrushOffAttackAction.LEFT);
}
return new BrushOffAttackAction(attacker.getId(), target
.getTargetType(), target.getTargetId(),
.getTargetType(), target.getId(),
BrushOffAttackAction.LEFT);
case BRUSH_RIGHT:
if (target == null) {
return new BrushOffAttackAction(attacker.getId(), i_target
.getTargetType(), i_target.getTargetId(),
.getTargetType(), i_target.getId(),
BrushOffAttackAction.RIGHT);
}
return new BrushOffAttackAction(attacker.getId(), target
.getTargetType(), target.getTargetId(),
.getTargetType(), target.getId(),
BrushOffAttackAction.RIGHT);
case BRUSH_BOTH:
if (target == null) {
return new BrushOffAttackAction(attacker.getId(), i_target
.getTargetType(), i_target.getTargetId(),
.getTargetType(), i_target.getId(),
BrushOffAttackAction.BOTH);
}
return new BrushOffAttackAction(attacker.getId(), target
.getTargetType(), target.getTargetId(),
.getTargetType(), target.getId(),
BrushOffAttackAction.BOTH);
/*
* case THRASH_INF : return new
Expand Down
14 changes: 7 additions & 7 deletions megamek/src/megamek/client/bot/princess/FireControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ ToHitData guessToHitModifierForWeapon(final Entity shooter,
if (targetState.isAirborneAero() && !shooterState.isAero()) {

// If the aero is attacking me, there is no range.
if (target.getTargetId() == shooter.getId()) {
if (target.getId() == shooter.getId()) {
distance = 0;
} else {
// Take into account altitude.
Expand Down Expand Up @@ -1286,7 +1286,7 @@ protected boolean isSubCommander(final Entity entity) {
} else if ((damageFraction < 0.5)
|| (target.getTargetType() == Targetable.TYPE_BUILDING)
|| (target.getTargetType() == Targetable.TYPE_HEX_CLEAR)
|| (owner.getGame().getEntity(target.getTargetId()) instanceof Infantry)) {
|| (owner.getGame().getEntity(target.getId()) instanceof Infantry)) {
return 0;
}

Expand Down Expand Up @@ -2200,7 +2200,7 @@ public SpotAction getSpotAction(FiringPlan plan, Entity spotter, FireControlStat
// otherwise, we still can't spot
if (!closestTargets.isEmpty()) {
Targetable target = closestTargets.get(Compute.randomInt(closestTargets.size()));
return new SpotAction(spotter.getId(), target.getTargetId());
return new SpotAction(spotter.getId(), target.getId());
}

return null;
Expand Down Expand Up @@ -2289,16 +2289,16 @@ FiringPlan getBestFiringPlan(final Entity shooter,
// Loop through each enemy and find the best plan for attacking them.
for (final Targetable enemy : enemies) {

if (owner.getBehaviorSettings().getIgnoredUnitTargets().contains(enemy.getTargetId())) {
if (owner.getBehaviorSettings().getIgnoredUnitTargets().contains(enemy.getId())) {
LogManager.getLogger().info(enemy.getDisplayName() + " is being explicitly ignored");
continue;
}

final boolean priorityTarget = owner.getPriorityUnitTargets().contains(enemy.getTargetId());
final boolean priorityTarget = owner.getPriorityUnitTargets().contains(enemy.getId());

// Skip retreating enemies so long as they haven't fired on me while retreating.
final int playerId = (enemy instanceof Entity) ? ((Entity) enemy).getOwnerId() : -1;
if (!priorityTarget && honorUtil.isEnemyBroken(enemy.getTargetId(), playerId,
if (!priorityTarget && honorUtil.isEnemyBroken(enemy.getId(), playerId,
owner.getForcedWithdrawal())) {
LogManager.getLogger().info(enemy.getDisplayName() + " is broken - ignoring");
continue;
Expand Down Expand Up @@ -3182,7 +3182,7 @@ public SearchlightAttackAction getSearchLightAction(Entity shooter, FiringPlan p
}

if (bestTarget != null) {
SearchlightAttackAction slaa = new SearchlightAttackAction(shooter.getId(), bestTarget.getTargetType(), bestTarget.getTargetId());
SearchlightAttackAction slaa = new SearchlightAttackAction(shooter.getId(), bestTarget.getTargetType(), bestTarget.getId());
return slaa;
}

Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/bot/princess/FiringPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ String getDebugDescription(boolean detailed) {
Set<Integer> targets = new HashSet<>();
// loop through all the targets for this firing plan, only show each target once.
for (WeaponFireInfo weaponFireInfo : this) {
if (!targets.contains(weaponFireInfo.getTarget().getTargetId())) {
if (!targets.contains(weaponFireInfo.getTarget().getId())) {
description.append(weaponFireInfo.getTarget().getDisplayName()).append(", ");
targets.add(weaponFireInfo.getTarget().getTargetId());
targets.add(weaponFireInfo.getTarget().getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ WeaponFireInfo getBestShot(Mounted weapon) {

for (Targetable target : getTargetableEnemyEntities(weapon.getEntity(), owner.getGame(), owner.getFireControlState())) {
final int ownerID = (target instanceof Entity) ? ((Entity) target).getOwnerId() : -1;
if (owner.getHonorUtil().isEnemyBroken(target.getTargetId(), ownerID, owner.getBehaviorSettings().isForcedWithdrawal())) {
if (owner.getHonorUtil().isEnemyBroken(target.getId(), ownerID, owner.getBehaviorSettings().isForcedWithdrawal())) {
LogManager.getLogger().info(target.getDisplayName() + " is broken - ignoring");
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Entity findClosestEnemy(Entity me, Coords position, Game game) {
List<Entity> enemies = getOwner().getEnemyEntities();
for (Entity e : enemies) {
// Also, skip withdrawing enemy bot units, to avoid humping disabled tanks and ejected mechwarriors
if (getOwner().getHonorUtil().isEnemyBroken(e.getTargetId(), e.getOwnerId(), getOwner().getForcedWithdrawal())) {
if (getOwner().getHonorUtil().isEnemyBroken(e.getId(), e.getOwnerId(), getOwner().getForcedWithdrawal())) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/bot/princess/PathRanker.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public Targetable findClosestEnemy(Entity me, Coords position, Game game,
// Also, skip withdrawing enemy bot units, to avoid humping disabled tanks and ejected
// MechWarriors
if (e.isAirborneAeroOnGroundMap() ||
getOwner().getHonorUtil().isEnemyBroken(e.getTargetId(), e.getOwnerId(),
getOwner().getHonorUtil().isEnemyBroken(e.getId(), e.getOwnerId(),
getOwner().getForcedWithdrawal())) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/bot/princess/PhysicalInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public double getExpectedDamage() {
protected PhysicalAttackAction buildAction(PhysicalAttackType attackType, int shooterId, Targetable target) {
if (attackType.isPunch()) {
int armId = PhysicalAttackType.RIGHT_PUNCH == attackType ? PunchAttackAction.RIGHT : PunchAttackAction.LEFT;
return new PunchAttackAction(shooterId, target.getTargetType(), target.getTargetId(), armId, false, false, false);
return new PunchAttackAction(shooterId, target.getTargetType(), target.getId(), armId, false, false, false);
} else if (attackType.isKick()) {
int legId = PhysicalAttackType.RIGHT_KICK == attackType ? KickAttackAction.RIGHT : KickAttackAction.LEFT;
return new KickAttackAction(shooterId, target.getTargetType(), target.getTargetId(), legId);
return new KickAttackAction(shooterId, target.getTargetType(), target.getId(), legId);
} else {
// todo handle other physical attack types.
return null;
Expand Down
10 changes: 5 additions & 5 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public UnitBehavior getUnitBehaviorTracker() {
}

double getDamageAlreadyAssigned(final Targetable target) {
final Integer targetId = target.getTargetId();
final Integer targetId = target.getId();
if (damageMap.containsKey(targetId)) {
return damageMap.get(targetId);
}
Expand Down Expand Up @@ -607,7 +607,7 @@ protected void calculateFiringTurn() {
// damageMap for the target enemy.
// while we're looping through all the shots anyway, send any firing mode changes
for (WeaponFireInfo shot : plan) {
Integer targetId = shot.getTarget().getTargetId();
Integer targetId = shot.getTarget().getId();
double existingTargetDamage = damageMap.getOrDefault(targetId, 0.0);
double newDamage = existingTargetDamage + shot.getExpectedDamage();
damageMap.put(targetId, newDamage);
Expand Down Expand Up @@ -1327,7 +1327,7 @@ protected void initFiring() {
final List<Targetable> potentialTargets = FireControl.getAllTargetableEnemyEntities(getLocalPlayer(),
getGame(), getFireControlState());
for (final Targetable target : potentialTargets) {
damageMap.put(target.getTargetId(), 0d);
damageMap.put(target.getId(), 0d);
}

getFireControlState().clearTransientData();
Expand Down Expand Up @@ -1457,7 +1457,7 @@ private void checkForDishonoredEnemies() {
continue;
}

if (getHonorUtil().isEnemyBroken(entity.getTargetId(), entity.getOwnerId(),
if (getHonorUtil().isEnemyBroken(entity.getId(), entity.getOwnerId(),
getForcedWithdrawal()) || !entity.isMilitary()) {
// If he'd just continued running, I would have let him
// go, but the bastard shot at me!
Expand Down Expand Up @@ -1569,7 +1569,7 @@ protected void initMovement() {
final List<Targetable> potentialTargets = FireControl.getAllTargetableEnemyEntities(
getLocalPlayer(), getGame(), fireControlState);
for (final Targetable target : potentialTargets) {
damageMap.put(target.getTargetId(), 0d);
damageMap.put(target.getId(), 0d);
}
} catch (Exception ignored) {

Expand Down
10 changes: 5 additions & 5 deletions megamek/src/megamek/client/bot/princess/WeaponFireInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,18 @@ WeaponAttackAction buildWeaponAttackAction() {
if (!(getWeapon().getType().hasFlag(WeaponType.F_ARTILLERY)
|| (getWeapon().getType() instanceof CapitalMissileWeapon
&& Compute.isGroundToGround(shooter, target)))) {
return new WeaponAttackAction(getShooter().getId(), getTarget().getTargetType(), getTarget().getTargetId(),
return new WeaponAttackAction(getShooter().getId(), getTarget().getTargetType(), getTarget().getId(),
getShooter().getEquipmentNum(getWeapon()));
} else {
return new ArtilleryAttackAction(getShooter().getId(), getTarget().getTargetType(), getTarget().getTargetId(),
return new ArtilleryAttackAction(getShooter().getId(), getTarget().getTargetType(), getTarget().getId(),
getShooter().getEquipmentNum(getWeapon()), getGame());
}
}

private WeaponAttackAction buildBombAttackAction(final int[] bombPayload) {
final WeaponAttackAction diveBomb = new WeaponAttackAction(getShooter().getId(),
getTarget().getTargetType(),
getTarget().getTargetId(),
getTarget().getId(),
getShooter().getEquipmentNum(getWeapon()));

diveBomb.setBombPayload(bombPayload);
Expand Down Expand Up @@ -645,11 +645,11 @@ WeaponAttackAction getWeaponAttackAction() {
if (!(getWeapon().getType().hasFlag(WeaponType.F_ARTILLERY)
|| (getWeapon().getType() instanceof CapitalMissileWeapon
&& Compute.isGroundToGround(shooter, target)))) {
setAction(new WeaponAttackAction(getShooter().getId(), getTarget().getTargetId(),
setAction(new WeaponAttackAction(getShooter().getId(), getTarget().getId(),
getShooter().getEquipmentNum(getWeapon())));
} else {
setAction(new ArtilleryAttackAction(getShooter().getId(), getTarget().getTargetType(),
getTarget().getTargetId(), getShooter().getEquipmentNum(getWeapon()),
getTarget().getId(), getShooter().getEquipmentNum(getWeapon()),
getGame()));
}
if (getAction() == null) {
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/commands/FireCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void fire(int weaponNum, Targetable target) {
}

WeaponAttackAction waa = new WeaponAttackAction(cen, target
.getTargetType(), target.getTargetId(), weaponNum);
.getTargetType(), target.getId(), weaponNum);

if (mounted.getLinked() != null && ((WeaponType) mounted.getType()).getAmmoType() != AmmoType.T_NA) {
Mounted ammoMount = mounted.getLinked();
Expand Down Expand Up @@ -249,7 +249,7 @@ private void doSearchlight(Targetable target) {

// create and queue a searchlight action
SearchlightAttackAction saa = new SearchlightAttackAction(cen, target.getTargetType(),
target.getTargetId());
target.getId());
attacks.addElement(saa);

// and add it into the game, temporarily
Expand Down
Loading

0 comments on commit 7736c49

Please sign in to comment.