Skip to content

Commit

Permalink
Merge branch 'master' into removeCPA
Browse files Browse the repository at this point in the history
  • Loading branch information
IllianiCBT committed Feb 1, 2025
2 parents 5e6b737 + 4a48f43 commit a68c3a8
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 208 deletions.
4 changes: 4 additions & 0 deletions MekHQ/docs/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ MEKHQ VERSION HISTORY:
+ PR #5930: Format Part Names as Italicized when Brand New
+ PR #5933: Fixed Overwriting of 'Brand New' Part State
+ Fix #5685: More control settings for autoLogistics
+ PR #5931: Refactored Part Handling in Resupply Module
+ Fix #5932: Added check for injuries that are not permanent before going on leave
+ PR #5946: Implemented Linked Scenarios for Interceptions



0.50.02 (2024-12-30 2130 UTC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ lblMissionsPanel.text=Missions
lblVocationalXP.text=Vocational XP per \u26A0
lblVocationalXP.tooltip=How much experience should be awarded per vocational experience check? This\
\ value is doubled while on any contract not classified as 'Garrison Type' (any contract that\
\ ends in 'Duty').
\ ends in 'Duty,' other than 'Relief Duty').
lblVocationalXPFrequency.text=Months
lblVocationalXPFrequency.tooltip=How many months occur between vocational experience checks?\
\ Characters will make a vocational experience check every time this many months has passed.
Expand Down
65 changes: 59 additions & 6 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
import static mekhq.campaign.market.contractMarket.ContractAutomation.performAutomatedActivation;
import static mekhq.campaign.mission.AtBContract.pickRandomCamouflage;
import static mekhq.campaign.mission.resupplyAndCaches.PerformResupply.performResupply;
import static mekhq.campaign.mission.resupplyAndCaches.Resupply.isProhibitedUnitType;
import static mekhq.campaign.mission.resupplyAndCaches.ResupplyUtilities.processAbandonedConvoy;
import static mekhq.campaign.parts.enums.PartQuality.QUALITY_A;
import static mekhq.campaign.personnel.backgrounds.BackgroundsController.randomMercenaryCompanyNameGenerator;
Expand Down Expand Up @@ -2578,17 +2579,56 @@ public void updatePartInUse(PartInUse partInUse, boolean ignoreMothballedUnits,
}

/**
* Create a data set detailing all the parts being used (or not) and their warehouse spares
* @param ignoreMothballedUnits don't count parts in mothballed units
* @param ignoreSparesUnderQuality don't count spare parts lower than this quality
* @return a Set of PartInUse data for display or inspection
* Analyzes the warehouse inventory and returns a data set that summarizes the usage state of
* all parts, including their use counts, store counts, and planned counts, while filtering
* based on specific conditions.
*
* <p>This method aggregates all parts currently in use or available as spares, while taking
* into account constraints like ignoring mothballed units or filtering spares below a specific
* quality. It uses a map structure to efficiently track and update parts during processing.</p>
*
* @param ignoreMothballedUnits If {@code true}, parts from mothballed units will not be
* included in the results.
* @param isResupply If {@code true}, specific units (e.g., prohibited unit types) are skipped
* based on the current context as defined in {@code Resupply.isProhibitedUnitType()}.
* @param ignoreSparesUnderQuality Spare parts of a lower quality than the specified value will
* be excluded from the results.
* @return A {@link Set} of {@link PartInUse} objects detailing the state of each relevant part,
* including:
* <ul>
* <li>Use count: How many of this part are currently in use.</li>
* <li>Store count: How many of this part are available as spares in the warehouse.</li>
* <li>Planned count: The quantity of this part included in acquisition orders or
* planned procurement.</li>
* <li>Requested stock: The target or default quantity to maintain, as derived from
* settings or requests.</li>
* </ul>
* Only parts with non-zero counts (use, store, or planned) will be included in the
* result.
*/

public Set<PartInUse> getPartsInUse(boolean ignoreMothballedUnits,
PartQuality ignoreSparesUnderQuality) {
boolean isResupply, PartQuality ignoreSparesUnderQuality) {
// java.util.Set doesn't supply a get(Object) method, so we have to use a
// java.util.Map
Map<PartInUse, PartInUse> inUse = new HashMap<>();
getWarehouse().forEachPart(incomingPart -> {
if (isResupply) {
Unit unit = incomingPart.getUnit();

Entity entity = null;
if (unit != null) {
entity = unit.getEntity();
}

if (entity != null) {
if (isProhibitedUnitType(entity, false)) {
return;
}
}
}


PartInUse partInUse = getPartInUse(incomingPart);
if (null == partInUse) {
return;
Expand Down Expand Up @@ -4823,7 +4863,7 @@ public boolean newDay() {
}

if (topUpWeekly && currentDay.getDayOfWeek() == DayOfWeek.MONDAY) {
int bought = stockUpPartsInUse(getPartsInUse(ignoreMothballed, ignoreSparesUnderQuality));
int bought = stockUpPartsInUse(getPartsInUse(ignoreMothballed, false, ignoreSparesUnderQuality));
addReport(String.format(resources.getString("weeklyStockCheck.text"), bought));
}

Expand Down Expand Up @@ -9046,4 +9086,17 @@ public ImageIcon getCampaignFactionIcon() {
}
return icon;
}

/**
* Checks if another active scenario has this scenarioID as it's linkedScenarioID and returns true if it finds one.
*/
public boolean checkLinkedScenario(int scenarioID) {
for (Scenario scenario : getScenarios()) {
if ((scenario.getLinkedScenario() == scenarioID)
&& (getScenario(scenario.getId()).getStatus().isCurrent())) {
return true;
}
}
return false;
}
}
16 changes: 16 additions & 0 deletions MekHQ/src/mekhq/campaign/mission/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class Scenario implements IPlayerSettings {
protected List<BotForce> botForces;
protected List<BotForceStub> botForcesStubs;

// linked Interception Scenario
private int linkedScenarioID;

// stores external id of bot forces
private Map<String, Entity> externalIDLookup;

Expand Down Expand Up @@ -150,6 +153,7 @@ public Scenario(String name) {
botForces = new ArrayList<>();
botForcesStubs = new ArrayList<>();
externalIDLookup = new HashMap<>();
linkedScenarioID = 0;

light = Light.DAY;
weather = Weather.CLEAR;
Expand Down Expand Up @@ -224,6 +228,14 @@ public void setDate(final @Nullable LocalDate date) {
this.date = date;
}

public int getLinkedScenario() {
return linkedScenarioID;
}

public void setlinkedScenarioID(int ScenarioID) {
linkedScenarioID = ScenarioID;
}

public boolean hasObjectives() {
return (scenarioObjectives != null) && !scenarioObjectives.isEmpty();
}
Expand Down Expand Up @@ -858,6 +870,7 @@ public boolean includesRequiredUnits(Campaign c) {
}

public boolean canStartScenario(Campaign c) {

if (!getStatus().isCurrent()) {
return false;
}
Expand Down Expand Up @@ -890,6 +903,7 @@ protected int writeToXMLBegin(final PrintWriter pw, int indent) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "startingAnySEy", startingAnySEy);
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "status", getStatus().name());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "id", id);
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "linkedScenarioID", linkedScenarioID);
if (null != stub) {
stub.writeToXML(pw, indent);
} else {
Expand Down Expand Up @@ -1025,6 +1039,8 @@ public static Scenario generateInstanceFromXML(Node wn, Campaign c, Version vers
retVal.setReport(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("forceStub")) {
retVal.stub = ForceStub.generateInstanceFromXML(wn2, version);
} else if (wn2.getNodeName().equalsIgnoreCase("linkedScenarioID")) {
retVal.linkedScenarioID = Integer.parseInt(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("date")) {
retVal.date = MHQXMLUtility.parseDate(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("cloaked")) {
Expand Down
Loading

0 comments on commit a68c3a8

Please sign in to comment.