|
27 | 27 | */
|
28 | 28 | package megamek.ai.dataset;
|
29 | 29 |
|
| 30 | +import java.util.List; |
| 31 | +import java.util.stream.Stream; |
| 32 | + |
| 33 | +import megamek.ai.utility.EntityFeatureUtils; |
30 | 34 | import megamek.client.ui.SharedUtility;
|
31 |
| -import megamek.common.Coords; |
| 35 | +import megamek.common.Compute; |
32 | 36 | import megamek.common.Entity;
|
| 37 | +import megamek.common.IAero; |
33 | 38 | import megamek.common.MovePath;
|
34 | 39 | import megamek.common.MoveStep;
|
35 |
| - |
36 |
| -import java.util.List; |
| 40 | +import megamek.common.UnitRole; |
37 | 41 |
|
38 | 42 | /**
|
39 |
| - * Represents a unit action. |
40 |
| - * @param id unit id |
41 |
| - * @param facing facing direction |
42 |
| - * @param fromX x coordinate of the starting position |
43 |
| - * @param fromY y coordinate of the starting position |
44 |
| - * @param toX x coordinate of the final position |
45 |
| - * @param toY y coordinate of the final position |
46 |
| - * @param hexesMoved number of hexes moved |
47 |
| - * @param distance distance moved |
48 |
| - * @param mpUsed movement points used |
49 |
| - * @param maxMp maximum movement points |
50 |
| - * @param mpP movement points percentage |
51 |
| - * @param heatP heat percentage |
52 |
| - * @param armorP armor percentage |
53 |
| - * @param internalP internal percentage |
54 |
| - * @param jumping jumping |
55 |
| - * @param prone prone |
56 |
| - * @param legal is move legal |
| 43 | + * UnitAction is a record that represents the action of a unit in the game. |
57 | 44 | * @author Luana Coppio
|
58 | 45 | */
|
59 |
| -public record UnitAction(int id, int teamId, int playerId, String chassis, String model, int facing, int fromX, int fromY, int toX, int toY, int hexesMoved, int distance, int mpUsed, |
60 |
| - int maxMp, double mpP, double heatP, double armorP, double internalP, boolean jumping, boolean prone, |
61 |
| - boolean legal, double chanceOfFailure, List<MovePath.MoveStepType> steps, boolean bot) { |
| 46 | +public record UnitAction(int id, int teamId, int playerId, String chassis, String model, int facing, |
| 47 | + int fromX, int fromY, int toX, int toY, int hexesMoved, int distance, |
| 48 | + int mpUsed, int maxMp, double mpP, double heatP, double armorP, double internalP, |
| 49 | + boolean jumping, boolean prone, boolean legal, double chanceOfFailure, |
| 50 | + List<MovePath.MoveStepType> steps, boolean bot, |
| 51 | + boolean hasEcm, int armor, int internal, int bv, int maxRange, int totalDamage, |
| 52 | + float armorFrontP, float armorLeftP, float armorRightP, float armorBackP, UnitRole role, |
| 53 | + List<Integer> weaponDamageFacingShortMediumLongRange) { |
62 | 54 |
|
63 |
| - public static UnitAction fromMovePath(MovePath movePath) { |
| 55 | + /** |
| 56 | + * Creates a UnitAction from a MovePath. |
| 57 | + * @param movePath |
| 58 | + * @return |
| 59 | + */ |
| 60 | + public static UnitAction fromMovePath(MovePath movePath) { |
64 | 61 | Entity entity = movePath.getEntity();
|
65 |
| - double chanceOfFailure = SharedUtility.getPSRList(movePath).stream().map(psr -> psr.getValue() / 36d).reduce(0.0, (a, b) -> a * b); |
| 62 | + double chanceOfFailure = SharedUtility.getPSRList(movePath).stream() |
| 63 | + .map(psr -> psr.getValue() / 36d) |
| 64 | + .reduce(0.0, (a, b) -> a * b); |
| 65 | + |
66 | 66 | var steps = movePath.getStepVector().stream().map(MoveStep::getType).toList();
|
| 67 | + |
67 | 68 | return new UnitAction(
|
68 |
| - entity.getId(), |
69 |
| - entity.getOwner() != null ? entity.getOwner().getTeam() : -1, |
70 |
| - entity.getOwner() != null ? entity.getOwner().getId() : -1, |
71 |
| - entity.getChassis(), |
72 |
| - entity.getModel(), |
73 |
| - movePath.getFinalFacing(), |
74 |
| - movePath.getStartCoords() != null ? movePath.getStartCoords().getX() : -1, |
75 |
| - movePath.getStartCoords() != null ? movePath.getStartCoords().getY() : -1, |
76 |
| - movePath.getFinalCoords() != null ? movePath.getFinalCoords().getX() : -1, |
77 |
| - movePath.getFinalCoords() != null ? movePath.getFinalCoords().getY() : -1, |
78 |
| - movePath.getHexesMoved(), |
79 |
| - movePath.getDistanceTravelled(), |
80 |
| - movePath.getMpUsed(), |
81 |
| - movePath.getMaxMP(), |
82 |
| - movePath.getMaxMP() > 0 ? (double) movePath.getMpUsed() / movePath.getMaxMP() : 0.0, |
83 |
| - entity.getHeatCapacity() > 0 ? entity.getHeat() / (double) entity.getHeatCapacity() : 0.0, |
84 |
| - entity.getArmorRemainingPercent(), |
85 |
| - entity.getInternalRemainingPercent(), |
86 |
| - movePath.isJumping(), |
87 |
| - movePath.getFinalProne(), |
88 |
| - movePath.isMoveLegal(), |
89 |
| - chanceOfFailure, |
90 |
| - steps, |
91 |
| - entity.getOwner().isBot() |
| 69 | + entity.getId(), |
| 70 | + entity.getOwner() != null ? entity.getOwner().getTeam() : -1, |
| 71 | + entity.getOwner() != null ? entity.getOwner().getId() : -1, |
| 72 | + entity.getChassis(), |
| 73 | + entity.getModel(), |
| 74 | + movePath.getFinalFacing(), |
| 75 | + movePath.getStartCoords() != null ? movePath.getStartCoords().getX() : -1, |
| 76 | + movePath.getStartCoords() != null ? movePath.getStartCoords().getY() : -1, |
| 77 | + movePath.getFinalCoords() != null ? movePath.getFinalCoords().getX() : -1, |
| 78 | + movePath.getFinalCoords() != null ? movePath.getFinalCoords().getY() : -1, |
| 79 | + movePath.getHexesMoved(), |
| 80 | + movePath.getDistanceTravelled(), |
| 81 | + movePath.getMpUsed(), |
| 82 | + movePath.getMaxMP(), |
| 83 | + movePath.getMaxMP() > 0 ? (double) movePath.getMpUsed() / movePath.getMaxMP() : 0.0, |
| 84 | + entity.getHeatCapacity() > 0 ? entity.getHeat() / (double) entity.getHeatCapacity() : 0.0, |
| 85 | + entity.getArmorRemainingPercent(), |
| 86 | + entity.getInternalRemainingPercent(), |
| 87 | + movePath.isJumping(), |
| 88 | + movePath.getFinalProne(), |
| 89 | + movePath.isMoveLegal(), |
| 90 | + chanceOfFailure, |
| 91 | + steps, |
| 92 | + entity.getOwner().isBot(), |
| 93 | + entity.hasActiveECM(), |
| 94 | + entity.getTotalArmor(), |
| 95 | + entity instanceof IAero aero ? aero.getSI() : entity.getTotalInternal(), |
| 96 | + entity.getInitialBV(), |
| 97 | + entity.getMaxWeaponRange(), |
| 98 | + Compute.computeTotalDamage(entity.getWeaponList()), |
| 99 | + EntityFeatureUtils.getTargetFrontHealthStats(entity), |
| 100 | + EntityFeatureUtils.getTargetLeftSideHealthStats(entity), |
| 101 | + EntityFeatureUtils.getTargetRightSideHealthStats(entity), |
| 102 | + EntityFeatureUtils.getTargetBackHealthStats(entity), |
| 103 | + entity.getRole(), |
| 104 | + entity.getWeaponList().stream().flatMap(weapon -> { |
| 105 | + int damage = Compute.computeTotalDamage(weapon); |
| 106 | + int facing = weapon.isRearMounted() ? -entity.getWeaponArc(weapon.getLocation()) : |
| 107 | + entity.getWeaponArc(weapon.getLocation()); |
| 108 | + int shortRange = weapon.getType().getShortRange(); |
| 109 | + int mediumRange = weapon.getType().getMediumRange(); |
| 110 | + int longRange = weapon.getType().getLongRange(); |
| 111 | + return Stream.of(damage, facing, shortRange, mediumRange, longRange); |
| 112 | + }).toList() |
92 | 113 | );
|
93 | 114 | }
|
94 |
| - |
95 |
| - public Coords currentPosition() { |
96 |
| - return new Coords(fromX, fromY); |
97 |
| - } |
98 |
| - |
99 |
| - public boolean isHuman() { |
100 |
| - return !bot; |
101 |
| - } |
102 |
| - |
103 |
| - public Coords finalPosition() { |
104 |
| - return new Coords(toX, toY); |
105 |
| - } |
106 | 115 | }
|
0 commit comments