Skip to content

Commit

Permalink
Merge pull request #4644 from Algebro7/refactor-contract-market
Browse files Browse the repository at this point in the history
Begin work on implementing CamOps Contract Market
  • Loading branch information
IllianiCBT authored Sep 25, 2024
2 parents b3b8be8 + dcf55ed commit ab4b419
Show file tree
Hide file tree
Showing 27 changed files with 1,280 additions and 760 deletions.
131 changes: 0 additions & 131 deletions MekHQ/data/CamOpsContractData2.xml

This file was deleted.

48 changes: 26 additions & 22 deletions MekHQ/data/universe/atbconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,32 @@ of 4. An entry of the form <entry>option</entry> has a weight of 1.
*Note that start and end dates are optional, but must
follow yyyy-MM-dd format. Planet names much match the
name in planets.xml exactly.-->
<hiringHalls>
<hall start="3031-01-01" end="3067-10-15">Outreach</hall>
<hall start="2700-01-01">Solaris</hall>
<hall start="3057-01-01">Arc-Royal</hall>
<hall start="3058-01-01" end="3081-03-15">Fletcher</hall>
<hall start="2650-01-01">Galatea</hall>
<hall start="3000-01-01">Westerhand</hall>
<hall start="3057-01-01" end="3081-03-15">Northwind</hall>
<hall start="3020-01-01">Herotitus</hall>
</hiringHalls>

</contractGeneration>

<!-- Values used for searching for an available ship to purchase. -->
<shipSearch>
<!-- The total cost of the search process -->
<shipSearchCost>100000</shipSearchCost>

<!-- The number of weeks required to complete the ship search. -->
<shipSearchLengthWeeks>4</shipSearchLengthWeeks>

<!-- The target number to for the dice roll to determine whether the ship search
<hiringHalls>
<hall start="3031-01-01" end="3067-10-15" level="great">Outreach</hall>
<hall start="2700-01-01" level="minor">Solaris</hall>
<hall start="3057-01-01" level="standard">Arc-Royal</hall>
<hall start="3058-01-01" end="3081-03-15" level="minor" >Fletcher</hall>
<hall start="2650-01-01" level="great">Galatea</hall>
<hall start="3000-01-01" level="great">Westerhand</hall>
<hall start="3057-01-01" end="3081-03-15" level="great">Northwind</hall>
<hall start="3020-01-01" level="minor">Herotitus</hall>
<hall start="2694-01-01" level="questionable">Antallos (Port Krin)</hall>
<hall start="2912-01-01" level="questionable">Astrokaszy</hall>
<hall start="3052-01-01" level="minor">Noisiel</hall>
<hall start="2811-01-01" end="3045-01-01" level="minor">Le Blanc</hall>
</hiringHalls>

</contractGeneration>

<!-- Values used for searching for an available ship to purchase. -->
<shipSearch>
<!-- The total cost of the search process -->
<shipSearchCost>100000</shipSearchCost>

<!-- The number of weeks required to complete the ship search. -->
<shipSearchLengthWeeks>4</shipSearchLengthWeeks>

<!-- The target number to for the dice roll to determine whether the ship search
was successful. Acceptable values for unitType are Dropship, Jumpship, and Warship.
If the target number is missing or commented out, that type of ship is not available
in a search. -->
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/data/universe/factions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ layeredForceIconLogoCategory - the category of the faction's logo piece
layeredForceIconLogoFilename - the filename of the faction's logo piece
tags - a comma-separated list of tags. Currently recognised tags: "is", "periphery",
"deep_periphery", "clan", "pirate", "merc", "trader", "minor", "rebel", "inactive", "hidden",
"abandoned", "chaos", "playable", "super"
"abandoned", "chaos", "playable", "super", "noble", "planetary_government", "corporation", "small"
start - the founding date of the faction
end - the date the faction ceases to exist
successor - unimplemented tag describing another faction code as the specified faction's successor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ botLance.CLAN=1:LLLLL,1:LLLLM,1:LLLMM|1:LLMMM,1:LMMMM,2:MMMMM,1:MMMMH,1:MMMHH|1:
botLance.CS=1:LLLLLL,2:LLLLLM,2:LLLLMM,1:LLLMMM|1:LLLMMM,1:LLMMMM,1:LMMMMM,1:MMMMMM,1:MMMMMH,1:MMMMHH|1:MMMHHH,1:MMHHHH,1:MHHHHH,1:HHHHHH,1:HHHHHA,1:HHHHAA|2:HHHAAA,1:HHAAAA,2:HAAAAA,1:AAAAAA

#The following are not required for AtB to function and are only used if atbconfig.xml is missing or broken
hiringHalls=3031-01-01,3067-10-15,Outreach|2700-01-01,,Solaris|3057-01-01,,Arc-Royal|3058-01-01,3081-03-15,Fletcher|2650-01-01,,Galatea|3000-01-01,,Westerhand|3057-01-01,3081-03-15,Northwind|3020-01-01,,Herotitus
hiringHalls=3031-01-01,3067-10-15,great,Outreach|2700-01-01,,minor,Solaris|3057-01-01,,standard,Arc-Royal|3058-01-01,3081-03-15,minor,Fletcher|2650-01-01,,great,Galatea|3000-01-01,,great,Westerhand|3057-01-01,3081-03-15,great,Northwind|3020-01-01,,minor,Herotitus|2694-01-01,,questionable,Antallos (Port Krin)|2912-01-01,,questionable,Astrokaszy|3052-01-01,,minor,Noisiel|2811-01-01,3045-01-01,minor,Le Blanc

shipSearchCost=100000
shipSearchLengthWeeks=4
Expand Down
2 changes: 2 additions & 0 deletions MekHQ/resources/mekhq/resources/Market.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ ContractMarketMethod.NONE.text=Disabled
ContractMarketMethod.NONE.toolTipText=The Contract Market is disabled.
ContractMarketMethod.ATB_MONTHLY.text=AtB Monthly
ContractMarketMethod.ATB_MONTHLY.toolTipText=This is the standard Against the Bot Contract Market, which refreshes monthly.
ContractMarketMethod.CAM_OPS.text=Campaign Ops (Under Development)
ContractMarketMethod.CAM_OPS.toolTipText=This is the standard Campaign Operations Contract Market, which refreshes monthly. This feature is currently under development and may not work properly.

# UnitMarketMethod Enum
UnitMarketMethod.NONE.text=Disabled
Expand Down
74 changes: 50 additions & 24 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@
import mekhq.campaign.log.HistoricalLogEntry;
import mekhq.campaign.log.LogEntry;
import mekhq.campaign.log.ServiceLogger;
import mekhq.campaign.market.ContractMarket;
import mekhq.campaign.market.PartsStore;
import mekhq.campaign.market.PersonnelMarket;
import mekhq.campaign.market.ShoppingList;
import mekhq.campaign.market.*;
import mekhq.campaign.market.contractMarket.AbstractContractMarket;
import mekhq.campaign.market.contractMarket.AtbMonthlyContractMarket;
import mekhq.campaign.market.unitMarket.AbstractUnitMarket;
import mekhq.campaign.market.unitMarket.DisabledUnitMarket;
import mekhq.campaign.mission.*;
Expand Down Expand Up @@ -210,8 +209,7 @@ public class Campaign implements ITechManager {

private Boolean fieldKitchenWithinCapacity;

// this is updated and used per gaming session, it is enabled/disabled via the
// Campaign options
// this is updated and used per gaming session, it is enabled/disabled via the Campaign options
// we're re-using the LogEntry class that is used to store Personnel entries
public LinkedList<LogEntry> inMemoryLogHistory = new LinkedList<>();

Expand Down Expand Up @@ -240,7 +238,7 @@ public class Campaign implements ITechManager {
private ShoppingList shoppingList;

private PersonnelMarket personnelMarket;
private ContractMarket contractMarket; // AtB
private AbstractContractMarket contractMarket;
private AbstractUnitMarket unitMarket;

private transient AbstractDeath death;
Expand Down Expand Up @@ -319,7 +317,7 @@ public Campaign() {
shoppingList = new ShoppingList();
news = new News(getGameYear(), id.getLeastSignificantBits());
setPersonnelMarket(new PersonnelMarket());
setContractMarket(new ContractMarket());
setContractMarket(new AtbMonthlyContractMarket());
setUnitMarket(new DisabledUnitMarket());
setDeath(new DisabledRandomDeath(getCampaignOptions(), false));
setDivorce(new DisabledRandomDivorce(getCampaignOptions()));
Expand Down Expand Up @@ -465,13 +463,11 @@ public void setPersonnelMarket(final PersonnelMarket personnelMarket) {
this.personnelMarket = personnelMarket;
}

// TODO : AbstractContractMarket : Swap to AbstractContractMarket
public ContractMarket getContractMarket() {
public AbstractContractMarket getContractMarket() {
return contractMarket;
}

// TODO : AbstractContractMarket : Swap to AbstractContractMarket
public void setContractMarket(final ContractMarket contractMarket) {
public void setContractMarket(final AbstractContractMarket contractMarket) {
this.contractMarket = contractMarket;
}

Expand Down Expand Up @@ -1662,17 +1658,15 @@ public boolean recruitPerson(Person p, PrisonerStatus prisonerStatus, boolean gm
* appropriate to the person's phenotype and the player's faction.
*
* @param person The Bloodname candidate
* @param ignoreDice If true, skips the random roll and assigns a Bloodname
* automatically
* @param ignoreDice If true, skips the random roll and assigns a Bloodname automatically
*/
public void checkBloodnameAdd(Person person, boolean ignoreDice) {
// if person is non-clan or does not have a phenotype
if (!person.isClanPersonnel() || person.getPhenotype().isNone()) {
return;
}

// Person already has a bloodname, we open up the dialog to ask if they want to
// keep the
// Person already has a bloodname, we open up the dialog to ask if they want to keep the
// current bloodname or assign a new one
if (!person.getBloodname().isEmpty()) {
int result = JOptionPane.showConfirmDialog(null,
Expand Down Expand Up @@ -2221,6 +2215,18 @@ public Person findBestInRole(PersonnelRole role, String skill) {
return findBestInRole(role, skill, null);
}

public @Nullable Person findBestAtSkill(String skill) {
Person person = null;
int highest = 0;
for (Person p : getActivePersonnel()) {
if (p.getSkill(skill) != null && p.getSkill(skill).getLevel() > highest) {
highest = p.getSkill(skill).getLevel();
person = p;
}
}
return person;
}

/**
* @return The list of all active {@link Person}s who qualify as technicians
* ({@link Person#isTech()}));
Expand Down Expand Up @@ -3512,7 +3518,7 @@ && getLocation().getJumpPath().getLastSystem().getId().equals(contract.getSystem
}

private void processNewDayATB() {
contractMarket.generateContractOffers(this); // TODO : AbstractContractMarket : Remove
contractMarket.generateContractOffers(this);

if ((getShipSearchExpiration() != null) && !getShipSearchExpiration().isAfter(getLocalDate())) {
setShipSearchExpiration(null);
Expand Down Expand Up @@ -6501,6 +6507,28 @@ public int getAtBUnitRatingMod() {
: reputation.getAtbModifier();
}

public int getReputationFactor() {
return switch (campaignOptions.getUnitRatingMethod()) {
case NONE -> 5;
case FLD_MAN_MERCS_REV -> getAtBUnitRatingMod() * 2;
case CAMPAIGN_OPS -> (int) ((getReputation().getReputationRating() * 0.2) + 0.5);
};
}

/**
* Returns the Strategy skill of the designated commander in the campaign.
*
* @return The value of the commander's strategy skill if a commander exists, otherwise 0.
*/
public int getCommanderStrategy() {
int cmdrStrategy = 0;
if (getFlaggedCommander() != null &&
getFlaggedCommander().getSkill(SkillType.S_STRATEGY) != null) {
cmdrStrategy = getFlaggedCommander().getSkill(SkillType.S_STRATEGY).getLevel();
}
return cmdrStrategy;
}

@Deprecated
public int getUnitRatingAsInteger() {
return getAtBUnitRatingMod();
Expand Down Expand Up @@ -7560,8 +7588,7 @@ public void initTimeInRank() {
LocalDate join = null;
for (LogEntry e : p.getPersonnelLog()) {
if (join == null) {
// If by some nightmare there is no date from the below, just use the first
// entry.
// If by some nightmare there is no date from the below, just use the first entry.
join = e.getDate();
}

Expand All @@ -7571,8 +7598,7 @@ public void initTimeInRank() {
}
}

// For that one in a billion chance the log is empty. Clone today's date and
// subtract a year
// For that one in a billion chance the log is empty. Clone today's date and subtract a year
p.setLastRankChangeDate((join != null) ? join : getLocalDate().minusYears(1));
}
}
Expand Down Expand Up @@ -7684,8 +7710,7 @@ public boolean checkOverDueLoans() {
}

/**
* Checks if a turnover prompt should be displayed based on campaign options and
* current date.
* Checks if a turnover prompt should be displayed based on campaign options and current date.
*
* @return An integer representing the user's choice:
* -1 if turnover prompt should not be displayed.
Expand Down Expand Up @@ -7747,7 +7772,8 @@ public int checkTurnoverPrompt() {
JOptionPane.INFORMATION_MESSAGE,
null,
options,
options[0]);
options[0]
);
}

/**
Expand Down
Loading

0 comments on commit ab4b419

Please sign in to comment.