Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
HammerGS committed Dec 5, 2024
2 parents 6fb89c7 + a003a43 commit bbb9507
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 299 deletions.
2 changes: 1 addition & 1 deletion MekHQ/data/forcegenerator/2823.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@
</model>
</chassis>
<chassis name='J. Edgar Light Hover Tank' unitType='Tank'>
<availability>CC:4IS:5,Periphery.Deep:5,FS:4,Periphery:5,TC:7,CS:4-,FWL:4,NIOPS:4-,DC:7</availability>
<availability>CC:4,IS:5,Periphery.Deep:5,FS:4,Periphery:5,TC:7,CS:4-,FWL:4,NIOPS:4-,DC:7</availability>
<model name=''>
<availability>General:8,Periphery.Deep:8,Periphery:8</availability>
</model>
Expand Down
4 changes: 2 additions & 2 deletions MekHQ/data/forcegenerator/3075.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9557,7 +9557,7 @@
</model>
</chassis>
<chassis name='Leopard' unitType='Dropship'>
<availability>MOC:8CC:7,HL:7,FRR:7,IS:8,Periphery.Deep:7,WOB:4,FS:7,BAN:2,Periphery:8,CS:4,LA:7,FWL:7,NIOPS:4,DC:7</availability>
<availability>MOC:8,CC:7,HL:7,FRR:7,IS:8,Periphery.Deep:7,WOB:4,FS:7,BAN:2,Periphery:8,CS:4,LA:7,FWL:7,NIOPS:4,DC:7</availability>
<model name='&apos;Pocket Warship&apos;'>
<availability>FWL:3,WOB:6</availability>
</model>
Expand Down Expand Up @@ -10639,7 +10639,7 @@
</model>
</chassis>
<chassis name='Maxim Heavy Hover Transport' unitType='Tank'>
<availability>CC:2FRR:4,CLAN:2,IS:2,Periphery.Deep:5,WOB:2-,MERC:2,FS:1,CIR:3,Periphery:2,CS:2-,LA:4,NIOPS:2-</availability>
<availability>CC:2,FRR:4,CLAN:2,IS:2,Periphery.Deep:5,WOB:2-,MERC:2,FS:1,CIR:3,Periphery:2,CS:2-,LA:4,NIOPS:2-</availability>
<model name=''>
<roles>apc</roles>
<availability>HL:2-,IS:4-,Periphery.Deep:8,Periphery:4-</availability>
Expand Down
4 changes: 2 additions & 2 deletions MekHQ/data/forcegenerator/3085.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4768,7 +4768,7 @@
</model>
</chassis>
<chassis name='Cyrano Gunship' unitType='VTOL'>
<availability>CC:3,MOC:3,CHH:2-,HL:3,CEI:2,FR:2,MERC:4,CDP:4,RA:2Periphery:4,ROS:6,NIOPS:6,CJF:2-</availability>
<availability>CC:3,MOC:3,CHH:2-,HL:3,CEI:2,FR:2,MERC:4,CDP:4,RA:2,Periphery:4,ROS:6,NIOPS:6,CJF:2-</availability>
<model name=''>
<roles>recon,escort</roles>
<availability>CC:4,CEI:4,ROS:5</availability>
Expand Down Expand Up @@ -11513,7 +11513,7 @@
</model>
</chassis>
<chassis name='Myrmidon Medium Tank' unitType='Tank'>
<availability>MOC:2CC:5,RA.OA:2,LA:5,ROS:5,FS:5,MERC:5,Periphery:2,DC:4</availability>
<availability>MOC:2,CC:5,RA.OA:2,LA:5,ROS:5,FS:5,MERC:5,Periphery:2,DC:4</availability>
<model name=''>
<availability>General:8</availability>
</model>
Expand Down
12 changes: 5 additions & 7 deletions MekHQ/resources/mekhq/resources/AtBStratCon.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ fromChainedScenario.text=Lance already deployed
lblDefensiveMinefieldCount.text=Defensive Minefield Count: %d
lblSelectIndividualUnits.text=Select individual units (%d max)

lblDefensivePostureInstructions.Text=<html>This lance is on a defensive deployment.\
<br>You may deploy additional infantry, battle armor, or minefields.</html>
lblLeadershipInstructions.Text=<html>The force commander's <i>Leadership</i> allows the deployment of additional\
\ auxiliary units - choose from the list below.</html>
lblFCLeadershipAvailable.Text=<html>Force commander's leadership: %d%s%s</html>
lblLeaderUnitsUsed.Text=<br/>%d units already assigned
lblLeadershipReinforcementsUnavailable.Text=<br/>Leadership reinforcements unavailable
lblDefensivePostureInstructions.Text=This lance is on a defensive deployment and you may deploy additional infantry, battle armor, or minefields.
lblLeadershipInstructions.Text=<html>The force commander's leadership allows the deployment of\
\ additional auxiliary units - choose from the list below.\
<br>\
<br><b>Available BV:</b> %s</html
selectForceForTemplate.Text=<html><b>Select a force from the list below.</b>\
<br>\
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/resources/mekhq/resources/Mission.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ContractCommandRights.INTEGRATED.toolTipText=<html><body style="width: 300px;">-
<br>- No map scouting (StratCon).\
<br>\
<br><i>Integrated command rights, standard for government forces, streamline command and control, particularly in large-scale operations involving multiple forces, ensuring effective collaboration without inter-service rivalry or confusion over command authority.</i></body></html>
ContractCommandRights.INTEGRATED.stratConText=The employer will make Lance assignments. Complete required scenarios to fulfill contract conditions.
ContractCommandRights.INTEGRATED.stratConText=The employer will make Lance assignments.<br>Complete required scenarios to fulfill contract conditions.

ContractCommandRights.HOUSE.text=House
ContractCommandRights.HOUSE.toolTipText=<html><body style="width: 300px;">- Keep your Campaign Victory Points (CVP) positive. Winning a non-initiated scenario: +1 CVP. Losing a non-initiated scenario: -1 CVP.\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,11 @@ public static LayeredForceIconOperationalStatus determineLayeredForceIconOperati
return NOT_OPERATIONAL;
}

switch (unit.getDamageState()) {
case Entity.DMG_NONE:
return FULLY_OPERATIONAL;
case Entity.DMG_LIGHT:
case Entity.DMG_MODERATE:
return SUBSTANTIALLY_OPERATIONAL;
case Entity.DMG_HEAVY:
case Entity.DMG_CRIPPLED:
return MARGINALLY_OPERATIONAL;
default:
return NOT_OPERATIONAL;
}
return switch (unit.getDamageState()) {
case Entity.DMG_NONE -> FULLY_OPERATIONAL;
case Entity.DMG_LIGHT, Entity.DMG_MODERATE -> SUBSTANTIALLY_OPERATIONAL;
case Entity.DMG_HEAVY, Entity.DMG_CRIPPLED -> MARGINALLY_OPERATIONAL;
default -> NOT_OPERATIONAL;
};
}
}
72 changes: 72 additions & 0 deletions MekHQ/src/mekhq/campaign/mission/AtBDynamicScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import megamek.common.Entity;
import megamek.common.annotations.Nullable;
import megamek.common.enums.SkillLevel;
import megamek.logging.MMLogger;
import mekhq.campaign.Campaign;
import mekhq.campaign.force.Force;
import mekhq.campaign.force.StrategicFormation;
import mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment;
import mekhq.campaign.mission.ScenarioForceTemplate.ForceGenerationMethod;
import mekhq.campaign.mission.atb.AtBScenarioModifier;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.SkillType;
import mekhq.campaign.rating.IUnitRating;
import mekhq.campaign.unit.Unit;
import mekhq.utilities.MHQXMLUtility;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Element;
Expand All @@ -39,6 +43,11 @@
import java.text.ParseException;
import java.util.*;

import static mekhq.campaign.mission.AtBDynamicScenarioFactory.getPlanetOwnerAlignment;
import static mekhq.campaign.mission.AtBDynamicScenarioFactory.getPlanetOwnerFaction;
import static mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment.Allied;
import static mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment.PlanetOwner;

/**
* Data structure intended to hold data relevant to AtB Dynamic Scenarios (AtB 3.0)
* @author NickAragua
Expand Down Expand Up @@ -86,6 +95,9 @@ public static class BenchedEntityData {
private transient Map<UUID, ScenarioForceTemplate> playerUnitTemplates;
private transient List<AtBScenarioModifier> scenarioModifiers;

private static final MMLogger logger = MMLogger.create(AtBDynamicScenario.class);


public AtBDynamicScenario() {
super();

Expand Down Expand Up @@ -594,4 +606,64 @@ public void clearAllForcesAndPersonnel(Campaign campaign) {
public String getBattlefieldControlDescription() {
return "";
}

/**
* Returns the total battle value (BV) either for allied forces or opposing forces in
* a given contract campaign, as per the parameter {@code isAllied}.
* <p>
* If {@code isAllied} is {@code true}, the method calculates the total BV for the allied
* forces inclusive of player forces. If {@code isAllied} is {@code false}, the total BV for
* opposing forces is calculated.
* <p>
* The calculation is done based on Bot forces attributed to each side. In the case of
* PlanetOwner, the alignment of the owner faction is considered to determine the ownership of
* Bot forces.
*
* @param campaign The campaign in which the forces are participating.
* @param isAllied A boolean value indicating whether to calculate the total BV for
* allied forces (if true) or opposing forces (if false).
* @return The total battle value (BV) either for the allied forces or
* opposing forces, as specified by the parameter isAllied.
*/
public int getTeamTotalBattleValue(Campaign campaign, boolean isAllied) {
AtBContract contract = getContract(campaign);
int totalBattleValue = 0;

for (BotForce botForce : getBotForces()) {
int battleValue = botForce.getTotalBV(campaign);

int team = botForce.getTeam();

if (team == PlanetOwner.ordinal()) {
String planetOwnerFaction = getPlanetOwnerFaction(contract, campaign.getLocalDate());
ForceAlignment forceAlignment = getPlanetOwnerAlignment(contract, planetOwnerFaction, campaign.getLocalDate());
team = forceAlignment.ordinal();
}

if (team <= Allied.ordinal()) {
if (isAllied) {
totalBattleValue += battleValue;
}
} else if (!isAllied) {
totalBattleValue += battleValue;
}
}

if (isAllied) {
Force playerForces = this.getForces(campaign);

for (UUID unitID : playerForces.getAllUnits(false)) {
try {
Unit unit = campaign.getUnit(unitID);
Entity entity = unit.getEntity();

totalBattleValue += entity.calculateBattleValue();
} catch (Exception ex) {
logger.warn(ex.getMessage(), ex);
}
}
}

return totalBattleValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ private static void correctNonAeroFlyerBehavior(List<Entity> entityList, int boa
* @param currentDate Current date.
* @return Faction code.
*/
private static String getPlanetOwnerFaction(AtBContract contract, LocalDate currentDate) {
static String getPlanetOwnerFaction(AtBContract contract, LocalDate currentDate) {
String factionCode = "MERC";

// planet owner is the first of the factions that owns the current planet.
Expand All @@ -3935,8 +3935,7 @@ private static String getPlanetOwnerFaction(AtBContract contract, LocalDate curr
* @param currentDate Current date.
* @return ForceAlignment.
*/
private static ForceAlignment getPlanetOwnerAlignment(AtBContract contract, String factionCode,
LocalDate currentDate) {
static ForceAlignment getPlanetOwnerAlignment(AtBContract contract, String factionCode, LocalDate currentDate) {
// if the faction is one of the planet owners, see if it's either the employer
// or opfor. If it's not, third-party.
if (contract.getSystem().getFactions(currentDate).contains(factionCode)) {
Expand Down
38 changes: 38 additions & 0 deletions MekHQ/src/mekhq/campaign/stratcon/StratconCampaignState.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import megamek.logging.MMLogger;
import mekhq.campaign.mission.AtBContract;
import org.w3c.dom.Node;

import javax.xml.namespace.QName;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -63,6 +66,8 @@ public class StratconCampaignState {
@XmlElement(name = "campaignTrack")
private final List<StratconTrackState> tracks;

private List<LocalDate> weeklyScenarios;

@XmlTransient
public AtBContract getContract() {
return contract;
Expand All @@ -74,10 +79,12 @@ public void setContract(AtBContract contract) {

public StratconCampaignState() {
tracks = new ArrayList<>();
weeklyScenarios = new ArrayList<>();
}

public StratconCampaignState(AtBContract contract) {
tracks = new ArrayList<>();
weeklyScenarios = new ArrayList<>();
setContract(contract);
}

Expand All @@ -102,6 +109,21 @@ public void addTrack(StratconTrackState track) {
tracks.add(track);
}

@XmlJavaTypeAdapter(value = LocalDateAdapter.class)
@XmlElementWrapper(name = "weeklyScenarios")
@XmlElement(name = "weeklyScenario")
public List<LocalDate> getWeeklyScenarios() {
return weeklyScenarios;
}

public void addWeeklyScenario(LocalDate weeklyScenario) {
weeklyScenarios.add(weeklyScenario);
}

public void setWeeklyScenarios(final List<LocalDate> weeklyScenarios) {
this.weeklyScenarios = weeklyScenarios;
}

public int getSupportPoints() {
return supportPoints;
}
Expand Down Expand Up @@ -232,4 +254,20 @@ public static StratconCampaignState Deserialize(Node xmlNode) {

return resultingCampaignState;
}

/**
* This adapter provides a way to convert between a LocalDate and the ISO-8601 string
* representation of the date that is used for XML marshaling and unmarshalling in JAXB.
*/
public static class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
@Override
public String marshal(LocalDate date) {
return date.toString();
}

@Override
public LocalDate unmarshal(String date) throws Exception {
return LocalDate.parse(date);
}
}
}
Loading

0 comments on commit bbb9507

Please sign in to comment.