Skip to content

Commit

Permalink
Introduced the beginnings of the Fame and Infamy module with batchall…
Browse files Browse the repository at this point in the history
… functionality

Implemented the Fame and Infamy module to track faction fame levels and batchall statements. Introduced the `BatchallFactions` and `FameAndInfamyController` classes for managing batchall usage and fame data. Updated relevant methods in `Campaign` and `AtBContract` to integrate this new feature, including XML writing and greeting adaptations.
  • Loading branch information
IllianiCBT committed Sep 24, 2024
1 parent df83fd5 commit 66bc4aa
Show file tree
Hide file tree
Showing 7 changed files with 871 additions and 162 deletions.
3 changes: 2 additions & 1 deletion MekHQ/resources/mekhq/resources/AtBContract.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ batchallStatementGeneric.text="We are The Clans. This world is ours by right. Id
batchallCloser.text=<br><br><b>Do you accept the Batchall?</b></html>
responseAccept.text=Accept Batchall
responseRefuse.text=Refuse Batchall
responseBringItOn.text=Bring It On

refusalConfirmation.text=Are you sure? This will increase the difficulty of the entire contract.
refusalConfirmation.text=Are you sure? %s will not forget this betrayal.
refusalReport.text=<center><b>YOU DARE TO REFUSE MY BATCHALL!?!</b></center>
482 changes: 482 additions & 0 deletions MekHQ/resources/mekhq/resources/FameAndInfamy.properties

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
import mekhq.campaign.universe.PlanetarySystem.PlanetarySystemEvent;
import mekhq.campaign.universe.eras.Era;
import mekhq.campaign.universe.eras.Eras;
import mekhq.campaign.universe.fameAndInfamy.BatchallFactions;
import mekhq.campaign.universe.fameAndInfamy.FameAndInfamyController;
import mekhq.campaign.universe.selectors.factionSelectors.AbstractFactionSelector;
import mekhq.campaign.universe.selectors.factionSelectors.DefaultFactionSelector;
import mekhq.campaign.universe.selectors.factionSelectors.RangedFactionSelector;
Expand Down Expand Up @@ -264,6 +266,7 @@ public class Campaign implements ITechManager {
private final CampaignSummary campaignSummary;
private final Quartermaster quartermaster;
private StoryArc storyArc;
private FameAndInfamyController fameAndInfamy;

private final transient ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.Campaign",
MekHQ.getMHQOptions().getLocale());
Expand Down Expand Up @@ -330,6 +333,7 @@ public Campaign() {
campaignSummary = new CampaignSummary(this);
quartermaster = new Quartermaster(this);
fieldKitchenWithinCapacity = false;
fameAndInfamy = new FameAndInfamyController();
}

/**
Expand Down Expand Up @@ -3589,7 +3593,7 @@ && getCampaignOptions().getRandomDependentMethod().isAgainstTheBot()
for (AtBContract contract : getActiveAtBContracts()) {
if (campaignOptions.isUseGenericBattleValue()) {
if (contract.getStartDate().equals(getLocalDate()) && getLocation().isOnPlanet()) {
if (contract.getEnemy().isClan()) {
if (BatchallFactions.usesBatchalls(contract.getEnemyCode())) {
contract.setBatchallAccepted(contract.initiateBatchall(this));
}
}
Expand Down Expand Up @@ -4810,6 +4814,10 @@ public List<String> getCurrentObjectives() {
return new ArrayList<>();
}

public FameAndInfamyController getFameAndInfamy() {
return fameAndInfamy;
}

public void writeToXML(final PrintWriter pw) {
int indent = 0;

Expand Down Expand Up @@ -4947,6 +4955,11 @@ public void writeToXML(final PrintWriter pw) {
storyArc.writeToXml(pw, indent);
}

// Fame and Infamy
if (fameAndInfamy != null) {
fameAndInfamy.writeToXml(pw, indent);
}

// Markets
getPersonnelMarket().writeToXML(pw, indent, this);

Expand Down
73 changes: 20 additions & 53 deletions MekHQ/src/mekhq/campaign/io/CampaignXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,20 @@
*/
package mekhq.campaign.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;

import javax.xml.parsers.DocumentBuilder;

import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.client.generator.RandomGenderGenerator;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.swing.util.PlayerColour;
import megamek.common.Entity;
import megamek.common.EntityMovementMode;
import megamek.common.Jumpship;
import megamek.common.Mek;
import megamek.common.MekSummaryCache;
import megamek.common.MiscType;
import megamek.common.Mounted;
import megamek.common.SmallCraft;
import megamek.common.Tank;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.icons.Camouflage;
import megamek.common.weapons.bayweapons.BayWeapon;
import megamek.logging.MMLogger;
import mekhq.MekHQ;
import mekhq.NullEntityException;
import mekhq.Utilities;
import mekhq.campaign.Campaign;
import mekhq.campaign.CampaignOptions;
import mekhq.campaign.CurrentLocation;
import mekhq.campaign.Kill;
import mekhq.campaign.RandomSkillPreferences;
import mekhq.campaign.Warehouse;
import mekhq.campaign.*;
import mekhq.campaign.againstTheBot.AtBConfiguration;
import mekhq.campaign.finances.Finances;
import mekhq.campaign.force.Force;
Expand All @@ -81,20 +44,8 @@
import mekhq.campaign.mission.Mission;
import mekhq.campaign.mission.Scenario;
import mekhq.campaign.mod.am.InjuryTypes;
import mekhq.campaign.parts.EnginePart;
import mekhq.campaign.parts.MekActuator;
import mekhq.campaign.parts.MekLocation;
import mekhq.campaign.parts.MissingEnginePart;
import mekhq.campaign.parts.MissingMekActuator;
import mekhq.campaign.parts.MissingPart;
import mekhq.campaign.parts.Part;
import mekhq.campaign.parts.equipment.AmmoBin;
import mekhq.campaign.parts.equipment.EquipmentPart;
import mekhq.campaign.parts.equipment.HeatSink;
import mekhq.campaign.parts.equipment.MASC;
import mekhq.campaign.parts.equipment.MissingAmmoBin;
import mekhq.campaign.parts.equipment.MissingEquipmentPart;
import mekhq.campaign.parts.equipment.MissingMASC;
import mekhq.campaign.parts.*;
import mekhq.campaign.parts.equipment.*;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.PersonnelOptions;
import mekhq.campaign.personnel.SkillType;
Expand All @@ -112,9 +63,18 @@
import mekhq.campaign.universe.Planet.PlanetaryEvent;
import mekhq.campaign.universe.PlanetarySystem.PlanetarySystemEvent;
import mekhq.campaign.universe.Systems;
import mekhq.campaign.universe.fameAndInfamy.FameAndInfamyController;
import mekhq.io.idReferenceClasses.PersonIdReference;
import mekhq.module.atb.AtBEventProcessor;
import mekhq.utilities.MHQXMLUtility;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilder;
import java.io.*;
import java.time.LocalDate;
import java.util.*;
import java.util.Map.Entry;

public class CampaignXmlParser {
private static final MMLogger logger = MMLogger.create(CampaignXmlParser.class);
Expand Down Expand Up @@ -298,6 +258,8 @@ public Campaign parse() throws CampaignXmlParseException, NullEntityException {
processSpecialAbilityNodes(retVal, wn, version);
} else if (xn.equalsIgnoreCase("storyArc")) {
processStoryArcNodes(retVal, wn, version);
} else if (xn.equalsIgnoreCase("fameAndInfamy")) {
processFameAndInfamyNodes(retVal, wn);
} else if (xn.equalsIgnoreCase("gameOptions")) {
retVal.getGameOptions().fillFromXML(wn.getChildNodes());
} else if (xn.equalsIgnoreCase("kills")) {
Expand Down Expand Up @@ -957,6 +919,11 @@ private static void processStoryArcNodes(Campaign retVal, Node wn, Version versi
retVal.useStoryArc(storyArc, false);
}

private static void processFameAndInfamyNodes(Campaign relativeValue, Node workingNode) {
logger.info("Loading Fame and Infamy Nodes from XML...");
FameAndInfamyController.parseFromXML(workingNode.getChildNodes(), relativeValue);
}

private static void processSpecialAbilityNodes(Campaign retVal, Node wn, Version version) {
logger.info("Loading Special Ability Nodes from XML...");

Expand Down
Loading

0 comments on commit 66bc4aa

Please sign in to comment.