Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Unit Quality Parameter to addNewUnit Method and Related Tests #4150

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Campaign.java
*
* Copyright (c) 2009 - Jay Lawson (jaylawson39 at yahoo.com). All Rights Reserved.
* Copyright (c) 2022 - The MegaMek Team. All Rights Reserved.
* Copyright (c) 2022 - 2024 The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand Down Expand Up @@ -672,7 +672,7 @@ public void purchaseShipSearchResult() {
: calculatePartTransitTime(Compute.d6(2) - 2);

getFinances().debit(TransactionType.UNIT_PURCHASE, getLocalDate(), cost, "Purchased " + en.getShortName());
addNewUnit(en, true, transitDays);
addNewUnit(en, true, transitDays, 3);
if (!getCampaignOptions().isInstantUnitMarketDelivery()) {
addReport("<font color='green'>Unit will be delivered in " + transitDays + " days.</font>");
}
Expand Down Expand Up @@ -1155,11 +1155,32 @@ public void addTestUnit(TestUnit tu) {
}

/**
* Add a new unit to the campaign.
* Add a new unit to the campaign and set its quality to 3 (D).
*
* @param en An <code>Entity</code> object that the new unit will be wrapped around
* @param en An <code>Entity</code> object that the new unit will be wrapped around
* @param allowNewPilots A boolean indicating whether to add new pilots for the unit
* @param days The number of days for the new unit to arrive
* @return The newly added unit
*/
public Unit addNewUnit(Entity en, boolean allowNewPilots, int days) {
return addNewUnit(en, allowNewPilots, days, 3);
}

/**
* Add a new unit to the campaign and set its quality.
*
* @param en An <code>Entity</code> object that the new unit will be wrapped around
* @param allowNewPilots A boolean indicating whether to add new pilots for the unit
* @param days The number of days for the new unit to arrive
* @param quality The quality of the new unit (0-5)
* @return The newly added unit
* @throws IllegalArgumentException If the quality is not within the valid range (0-5)
*/
public Unit addNewUnit(Entity en, boolean allowNewPilots, int days, int quality) {
if ((quality < 0) || (quality > 5)) {
throw new IllegalArgumentException("Invalid quality in mekhq/campaign/Campaign.java/addNewUnit: " + quality);
}

Unit unit = new Unit(en, this);
getHangar().addUnit(unit);

Expand Down Expand Up @@ -1192,6 +1213,8 @@ public Unit addNewUnit(Entity en, boolean allowNewPilots, int days) {
}
unit.resetPilotAndEntity();

unit.setQuality(quality);

// Assign an entity ID to our new unit
if (Entity.NONE == en.getId()) {
en.setId(game.getNextEntityId());
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/Quartermaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum PartAcquisitionResult {
PlanetSpecificFailure,
Success
}

private final Campaign campaign;

/**
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import megamek.common.icons.Camouflage;
import megamek.common.loaders.EntityLoadingException;
import mekhq.MekHQ;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.event.MissionChangedEvent;
import mekhq.campaign.finances.Money;
Expand All @@ -46,6 +45,7 @@
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Factions;
import mekhq.campaign.universe.RandomFactionGenerator;
import mekhq.utilities.MHQXMLUtility;
import org.apache.logging.log4j.LogManager;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/mission/Loot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import megamek.common.MechSummary;
import megamek.common.MechSummaryCache;
import megamek.common.loaders.EntityLoadingException;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.parts.Part;
import mekhq.utilities.MHQXMLUtility;
import org.apache.logging.log4j.LogManager;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import mekhq.campaign.personnel.generator.AbstractPersonnelGenerator;
import mekhq.campaign.personnel.ranks.Rank;
import mekhq.campaign.unit.Unit;
import mekhq.campaign.universe.*;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.companyGeneration.AtBRandomMechParameters;
import mekhq.campaign.universe.companyGeneration.CompanyGenerationOptions;
import mekhq.campaign.universe.companyGeneration.CompanyGenerationPersonTracker;
Expand Down
6 changes: 1 addition & 5 deletions MekHQ/src/mekhq/gui/dialog/PersonnelMarketDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import megamek.client.ui.preferences.*;
import megamek.client.ui.swing.MechViewPanel;
import megamek.codeUtilities.StringUtility;
import megamek.common.Aero;
import megamek.common.Compute;
import megamek.common.Entity;
import megamek.common.Mech;
import megamek.common.Tank;
import megamek.common.*;
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/panes/UnitMarketPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package mekhq.gui.panes;

import megamek.client.ui.models.XTableColumnModel;
import megamek.client.ui.panels.EntityImagePanel;
import megamek.client.ui.panes.EntityViewPane;
import megamek.client.ui.preferences.*;
Expand All @@ -33,7 +34,6 @@
import mekhq.campaign.market.unitMarket.UnitMarketOffer;
import mekhq.gui.baseComponents.AbstractMHQSplitPane;
import mekhq.gui.model.UnitMarketTableModel;
import megamek.client.ui.models.XTableColumnModel;
import mekhq.gui.sorter.WeightClassSorter;
import org.apache.logging.log4j.LogManager;

Expand Down
1 change: 0 additions & 1 deletion MekHQ/unittests/mekhq/campaign/QuartermasterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import mekhq.campaign.finances.Money;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.parts.*;
import mekhq.campaign.parts.equipment.EquipmentPart;
import mekhq.campaign.unit.TestUnit;
import mekhq.campaign.unit.Unit;
import org.junit.jupiter.api.Test;
Expand Down
Loading