|
22 | 22 | import megamek.common.Entity;
|
23 | 23 | import megamek.common.annotations.Nullable;
|
24 | 24 | import megamek.common.enums.SkillLevel;
|
| 25 | +import megamek.logging.MMLogger; |
25 | 26 | import mekhq.campaign.Campaign;
|
| 27 | +import mekhq.campaign.force.Force; |
26 | 28 | import mekhq.campaign.force.StrategicFormation;
|
| 29 | +import mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment; |
27 | 30 | import mekhq.campaign.mission.ScenarioForceTemplate.ForceGenerationMethod;
|
28 | 31 | import mekhq.campaign.mission.atb.AtBScenarioModifier;
|
29 | 32 | import mekhq.campaign.personnel.Person;
|
30 | 33 | import mekhq.campaign.personnel.SkillType;
|
31 | 34 | import mekhq.campaign.rating.IUnitRating;
|
| 35 | +import mekhq.campaign.unit.Unit; |
32 | 36 | import mekhq.utilities.MHQXMLUtility;
|
33 | 37 | import org.apache.commons.lang3.StringUtils;
|
34 | 38 | import org.w3c.dom.Element;
|
|
39 | 43 | import java.text.ParseException;
|
40 | 44 | import java.util.*;
|
41 | 45 |
|
| 46 | +import static mekhq.campaign.mission.AtBDynamicScenarioFactory.getPlanetOwnerAlignment; |
| 47 | +import static mekhq.campaign.mission.AtBDynamicScenarioFactory.getPlanetOwnerFaction; |
| 48 | +import static mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment.Allied; |
| 49 | +import static mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment.PlanetOwner; |
| 50 | + |
42 | 51 | /**
|
43 | 52 | * Data structure intended to hold data relevant to AtB Dynamic Scenarios (AtB 3.0)
|
44 | 53 | * @author NickAragua
|
@@ -86,6 +95,9 @@ public static class BenchedEntityData {
|
86 | 95 | private transient Map<UUID, ScenarioForceTemplate> playerUnitTemplates;
|
87 | 96 | private transient List<AtBScenarioModifier> scenarioModifiers;
|
88 | 97 |
|
| 98 | + private static final MMLogger logger = MMLogger.create(AtBDynamicScenario.class); |
| 99 | + |
| 100 | + |
89 | 101 | public AtBDynamicScenario() {
|
90 | 102 | super();
|
91 | 103 |
|
@@ -594,4 +606,64 @@ public void clearAllForcesAndPersonnel(Campaign campaign) {
|
594 | 606 | public String getBattlefieldControlDescription() {
|
595 | 607 | return "";
|
596 | 608 | }
|
| 609 | + |
| 610 | + /** |
| 611 | + * Returns the total battle value (BV) either for allied forces or opposing forces in |
| 612 | + * a given contract campaign, as per the parameter {@code isAllied}. |
| 613 | + * <p> |
| 614 | + * If {@code isAllied} is {@code true}, the method calculates the total BV for the allied |
| 615 | + * forces inclusive of player forces. If {@code isAllied} is {@code false}, the total BV for |
| 616 | + * opposing forces is calculated. |
| 617 | + * <p> |
| 618 | + * The calculation is done based on Bot forces attributed to each side. In the case of |
| 619 | + * PlanetOwner, the alignment of the owner faction is considered to determine the ownership of |
| 620 | + * Bot forces. |
| 621 | + * |
| 622 | + * @param campaign The campaign in which the forces are participating. |
| 623 | + * @param isAllied A boolean value indicating whether to calculate the total BV for |
| 624 | + * allied forces (if true) or opposing forces (if false). |
| 625 | + * @return The total battle value (BV) either for the allied forces or |
| 626 | + * opposing forces, as specified by the parameter isAllied. |
| 627 | + */ |
| 628 | + public int getTeamTotalBattleValue(Campaign campaign, boolean isAllied) { |
| 629 | + AtBContract contract = getContract(campaign); |
| 630 | + int totalBattleValue = 0; |
| 631 | + |
| 632 | + for (BotForce botForce : getBotForces()) { |
| 633 | + int battleValue = botForce.getTotalBV(campaign); |
| 634 | + |
| 635 | + int team = botForce.getTeam(); |
| 636 | + |
| 637 | + if (team == PlanetOwner.ordinal()) { |
| 638 | + String planetOwnerFaction = getPlanetOwnerFaction(contract, campaign.getLocalDate()); |
| 639 | + ForceAlignment forceAlignment = getPlanetOwnerAlignment(contract, planetOwnerFaction, campaign.getLocalDate()); |
| 640 | + team = forceAlignment.ordinal(); |
| 641 | + } |
| 642 | + |
| 643 | + if (team <= Allied.ordinal()) { |
| 644 | + if (isAllied) { |
| 645 | + totalBattleValue += battleValue; |
| 646 | + } |
| 647 | + } else if (!isAllied) { |
| 648 | + totalBattleValue += battleValue; |
| 649 | + } |
| 650 | + } |
| 651 | + |
| 652 | + if (isAllied) { |
| 653 | + Force playerForces = this.getForces(campaign); |
| 654 | + |
| 655 | + for (UUID unitID : playerForces.getAllUnits(false)) { |
| 656 | + try { |
| 657 | + Unit unit = campaign.getUnit(unitID); |
| 658 | + Entity entity = unit.getEntity(); |
| 659 | + |
| 660 | + totalBattleValue += entity.calculateBattleValue(); |
| 661 | + } catch (Exception ex) { |
| 662 | + logger.warn(ex.getMessage(), ex); |
| 663 | + } |
| 664 | + } |
| 665 | + } |
| 666 | + |
| 667 | + return totalBattleValue; |
| 668 | + } |
597 | 669 | }
|
0 commit comments