Skip to content

Commit

Permalink
Merge pull request MegaMek#5786 from rjhancock/mmlogger-migrations
Browse files Browse the repository at this point in the history
MMLogger Migrations
  • Loading branch information
HammerGS authored Aug 8, 2024
2 parents d29fa8c + b736b42 commit c8a471f
Show file tree
Hide file tree
Showing 14 changed files with 1,912 additions and 1,455 deletions.
899 changes: 373 additions & 526 deletions megamek/docs/1-Readme/readme.txt

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions megamek/src/megamek/MegaMek.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public static void main(String... args) {
}

public static void initializeLogging(final String originProject) {
String message = getUnderlyingInformation(originProject);
logger.info(message);
logger.info(getUnderlyingInformation(originProject));
}

public static SuitePreferences getMMPreferences() {
Expand Down Expand Up @@ -219,8 +218,7 @@ public static String getMemoryUsed() {
* @param args the arguments to the dedicated server.
*/
private static void startDedicatedServer(String... args) {
String message = String.format(MMLoggingConstants.SC_STARTING_DEDICATED_SERVER, Arrays.toString(args));
logger.info(message);
logger.info(MMLoggingConstants.SC_STARTING_DEDICATED_SERVER, Arrays.toString(args));
DedicatedServer.start(args);
}

Expand Down Expand Up @@ -251,8 +249,7 @@ private static void startHost(String... args) {
MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

String message = String.format(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));
logger.info(message);
logger.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand Down Expand Up @@ -295,8 +292,7 @@ private static void startQuickLoad(String... args) {
MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

String message = String.format(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));
logger.info(message);
logger.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand Down Expand Up @@ -338,8 +334,7 @@ private static void startClient(String... args) {
null, MMConstants.DEFAULT_PORT, MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

String message = String.format(MMLoggingConstants.SC_STARTING_CLIENT_SERVER, Arrays.toString(args));
logger.info(message);
logger.info(MMLoggingConstants.SC_STARTING_CLIENT_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand Down
200 changes: 120 additions & 80 deletions megamek/src/megamek/client/bot/princess/AeroPathUtil.java

Large diffs are not rendered by default.

301 changes: 180 additions & 121 deletions megamek/src/megamek/client/bot/princess/ArtilleryTargetingControl.java

Large diffs are not rendered by default.

647 changes: 342 additions & 305 deletions megamek/src/megamek/client/bot/princess/BasicPathRanker.java

Large diffs are not rendered by default.

128 changes: 80 additions & 48 deletions megamek/src/megamek/client/bot/princess/BehaviorSettings.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
/*
* MegaMek - Copyright (C) 2003 Ben Mazur (bmazur@sev.org)
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* This file is part of MegaMek.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.bot.princess;

import megamek.codeUtilities.StringUtility;
import megamek.common.annotations.Nullable;
import megamek.common.util.StringUtil;
import megamek.utilities.xml.MMXMLUtility;
import org.apache.logging.log4j.LogManager;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import megamek.codeUtilities.StringUtility;
import megamek.common.annotations.Nullable;
import megamek.common.util.StringUtil;
import megamek.logging.MMLogger;
import megamek.utilities.xml.MMXMLUtility;

/**
* @author Deric "Netzilla" Page (deric dot page at usa dot net)
* @since 17-Aug-2013 10:47 PM
*/
public class BehaviorSettings implements Serializable {
//region Variable Declarations
private static final MMLogger logger = MMLogger.create(BehaviorSettings.class);

// region Variable Declarations
private static final long serialVersionUID = -1895924639830817372L;

static final double[] SELF_PRESERVATION_VALUES = {
Expand All @@ -46,7 +55,8 @@ public class BehaviorSettings implements Serializable {
20,
22.5,
25,
30};
30 };

static final int[] FALL_SHAME_VALUES = {
10,
40,
Expand All @@ -58,7 +68,8 @@ public class BehaviorSettings implements Serializable {
500,
500,
500,
500};
500 };

protected static final double[] BRAVERY = {
0.1,
0.3,
Expand All @@ -70,7 +81,8 @@ public class BehaviorSettings implements Serializable {
2.1,
2.4,
2.7,
3.0};
3.0 };

static final double[] HYPER_AGGRESSION_VALUES = {
0.25,
0.5,
Expand All @@ -82,7 +94,8 @@ public class BehaviorSettings implements Serializable {
3.5,
10,
50,
500};
500 };

static final double[] HERD_MENTALITY_VALUES = {
0.1,
0.2,
Expand All @@ -94,7 +107,7 @@ public class BehaviorSettings implements Serializable {
1.4,
1.6,
1.8,
2.0};
2.0 };

private String description = BehaviorSettingsFactory.DEFAULT_BEHAVIOR_DESCRIPTION;

Expand All @@ -107,13 +120,13 @@ public class BehaviorSettings implements Serializable {
private CardinalEdge destinationEdge = CardinalEdge.NONE; // Which edge am I trying to reach?
private CardinalEdge retreatEdge = CardinalEdge.NEAREST; // To which edge will my units flee when crippled?
private final Set<String> strategicBuildingTargets = new HashSet<>(); // What (besides enemy units) do I want to
// blow up?
// blow up?
private final Set<Integer> priorityUnitTargets = new HashSet<>(); // What units do I especially want to blow up?
private int herdMentalityIndex = 5; // How close do I want to stick to my teammates?
private int braveryIndex = 5; // How quickly will I try to escape once damaged?

private final Set<Integer> ignoredUnitTargets = new HashSet<>();
//endregion Variable Declarations
// endregion Variable Declarations

public BehaviorSettings() {

Expand Down Expand Up @@ -155,16 +168,17 @@ public boolean shouldGoHome() {
return destinationEdge != CardinalEdge.NONE;
}


/**
* @return TRUE if I should flee off the board even if I am not crippled or Forced Withdrawal is not in effect.
* @return TRUE if I should flee off the board even if I am not crippled or
* Forced Withdrawal is not in effect.
*/
public boolean shouldAutoFlee() {
return autoFlee;
}

/**
* @param autoFlee Set TRUE if I should flee off the board even if I am not crippled or Forced Withdrawal is not in
* @param autoFlee Set TRUE if I should flee off the board even if I am not
* crippled or Forced Withdrawal is not in
* effect.
*/
public void setAutoFlee(final boolean autoFlee) {
Expand All @@ -181,7 +195,7 @@ public String getDescription() {
}

/**
* Sets the name for this type of behavior. Must be unique in order to save.
* Sets the name for this type of behavior. Must be unique in order to save.
* Throws a PrincessException when the description is empty.
*
* @param description The name to be used.
Expand Down Expand Up @@ -301,7 +315,8 @@ void removePriorityUnit(final String id) {
}

/**
* When this is true, Princess will follow the Forced Withdrawal rules from Total Warfare.
* When this is true, Princess will follow the Forced Withdrawal rules from
* Total Warfare.
*
* @return Should Princess follow the Forced Withdrawal rules?
*/
Expand All @@ -310,7 +325,8 @@ public boolean isForcedWithdrawal() {
}

/**
* When this is true, Princess will follow the Forced Withdrawal rules from Total Warfare.
* When this is true, Princess will follow the Forced Withdrawal rules from
* Total Warfare.
*
* @param forcedWithdrawal Should Princess follow the Forced Withdrawal rules?
*/
Expand All @@ -319,7 +335,8 @@ public void setForcedWithdrawal(final boolean forcedWithdrawal) {
}

/**
* When this is true, Princess will follow the Forced Withdrawal rules from Total Warfare.
* When this is true, Princess will follow the Forced Withdrawal rules from
* Total Warfare.
*
* @param forcedWithdrawal Should Princess follow the Forced Withdrawal rules?
*/
Expand Down Expand Up @@ -402,7 +419,8 @@ int getFallShameValue() {

/**
* @param index The index of the {@link #FALL_SHAME_VALUES} sought.
* @return The value at the given index. Indexes less than 0 are treated as 0 and indexes greater than 10 are
* @return The value at the given index. Indexes less than 0 are treated as 0
* and indexes greater than 10 are
* treated as 10.
*/
protected int getFallShameValue(final int index) {
Expand Down Expand Up @@ -448,7 +466,8 @@ public int getHerdMentalityIndex() {
/**
* How close do I want to stick to my teammates?
*
* @param index The index [0-10] of the herd mentality value that should be used.
* @param index The index [0-10] of the herd mentality value that should be
* used.
* @return The herd mentality value at the specified index.
*/
protected double getHerdMentalityValue(final int index) {
Expand All @@ -458,7 +477,8 @@ protected double getHerdMentalityValue(final int index) {
/**
* How close do I want to stick to my teammates?
*
* @param herdMentalityIndex The index [0-10] of the herd mentality that should be used.
* @param herdMentalityIndex The index [0-10] of the herd mentality that should
* be used.
*/
public void setHerdMentalityIndex(final int herdMentalityIndex) {
this.herdMentalityIndex = validateIndex(herdMentalityIndex);
Expand All @@ -467,7 +487,8 @@ public void setHerdMentalityIndex(final int herdMentalityIndex) {
/**
* How close do I want to stick to my teammates?
*
* @param index The index ["0"-"10"] of the herd mentality value that should be used.
* @param index The index ["0"-"10"] of the herd mentality value that should be
* used.
*/
public void setHerdMentalityIndex(final String index) throws PrincessException {
try {
Expand Down Expand Up @@ -502,7 +523,8 @@ public void setDestinationEdge(final @Nullable CardinalEdge destinationEdge) {
/**
* Princess's home edge.
*
* @param destinationEdge the index of the {@link CardinalEdge} princess should flee to. See {@link CardinalEdge#getIndex()}
* @param destinationEdge the index of the {@link CardinalEdge} princess should
* flee to. See {@link CardinalEdge#getIndex()}
*/
public void setDestinationEdge(final int destinationEdge) {
setDestinationEdge(CardinalEdge.getCardinalEdge(destinationEdge));
Expand All @@ -511,7 +533,8 @@ public void setDestinationEdge(final int destinationEdge) {
/**
* Princess's home edge.
*
* @param destinationEdge the index of the {@link CardinalEdge} princess should flee to. See {@link CardinalEdge#getIndex()}
* @param destinationEdge the index of the {@link CardinalEdge} princess should
* flee to. See {@link CardinalEdge#getIndex()}
*/
public void setDestinationEdge(final String destinationEdge) throws PrincessException {
try {
Expand Down Expand Up @@ -546,7 +569,8 @@ public void setRetreatEdge(final @Nullable CardinalEdge retreatEdge) {
/**
* Princess's home edge.
*
* @param retreatEdge the index of the {@link CardinalEdge} princess should flee to. See {@link CardinalEdge#getIndex()}
* @param retreatEdge the index of the {@link CardinalEdge} princess should flee
* to. See {@link CardinalEdge#getIndex()}
*/
public void setRetreatEdge(final int retreatEdge) {
setRetreatEdge(CardinalEdge.getCardinalEdge(retreatEdge));
Expand All @@ -555,7 +579,8 @@ public void setRetreatEdge(final int retreatEdge) {
/**
* Princess's home edge.
*
* @param retreatEdge the index of the {@link CardinalEdge} princess should flee to. See {@link CardinalEdge#getIndex()}
* @param retreatEdge the index of the {@link CardinalEdge} princess should flee
* to. See {@link CardinalEdge#getIndex()}
*/
public void setRetreatEdge(final String retreatEdge) throws PrincessException {
try {
Expand Down Expand Up @@ -596,7 +621,8 @@ protected double getHyperAggressionValue(final int index) {
/**
* How close to I want to get to my enemies?
*
* @param hyperAggressionIndex The index [0-10] of the hyper aggression value to be used.
* @param hyperAggressionIndex The index [0-10] of the hyper aggression value to
* be used.
*/
public void setHyperAggressionIndex(final int hyperAggressionIndex) {
this.hyperAggressionIndex = validateIndex(hyperAggressionIndex);
Expand Down Expand Up @@ -651,7 +677,8 @@ public double getSelfPreservationValue(int index) {
/**
* How worried about enemy damage am I?
*
* @param selfPreservationIndex The index [0-10] of the self preservation value to be used.
* @param selfPreservationIndex The index [0-10] of the self preservation value
* to be used.
*/
public void setSelfPreservationIndex(final int selfPreservationIndex) {
this.selfPreservationIndex = validateIndex(selfPreservationIndex);
Expand Down Expand Up @@ -727,10 +754,11 @@ public boolean isDefault() {
/**
* Returns an XML representation of the behavior settings.
*
* @return An XML {@link org.w3c.dom.Element} describing this behavior settings object.
* @return An XML {@link org.w3c.dom.Element} describing this behavior settings
* object.
*/
Element toXml(final Document doc,
final boolean includeTargets) {
final boolean includeTargets) {
try {
final Element behavior = doc.createElement("behavior");

Expand Down Expand Up @@ -800,7 +828,7 @@ Element toXml(final Document doc,

return behavior;
} catch (final Exception e) {
LogManager.getLogger().error("", e);
logger.error(e, "Exception Occurred.");
}

return null;
Expand All @@ -814,11 +842,15 @@ public String toLog() {
out.append("\n\t Destination Edge: ").append(getDestinationEdge());
out.append("\n\t Retreat Edge: ").append(getRetreatEdge());
out.append("\n\t Forced Withdrawal: ").append(isForcedWithdrawal());
out.append("\n\t Self Preservation: ").append(getSelfPreservationIndex()).append(":").append(getSelfPreservationValue(getSelfPreservationIndex()));
out.append("\n\t Hyper Aggression: ").append(getHyperAggressionIndex()).append(":").append(getHyperAggressionValue(getHyperAggressionIndex()));
out.append("\n\t Fall Shame: ").append(getFallShameIndex()).append(":").append(getFallShameValue(getFallShameIndex()));
out.append("\n\t Self Preservation: ").append(getSelfPreservationIndex()).append(":")
.append(getSelfPreservationValue(getSelfPreservationIndex()));
out.append("\n\t Hyper Aggression: ").append(getHyperAggressionIndex()).append(":")
.append(getHyperAggressionValue(getHyperAggressionIndex()));
out.append("\n\t Fall Shame: ").append(getFallShameIndex()).append(":")
.append(getFallShameValue(getFallShameIndex()));
out.append("\n\t Bravery: ").append(getBraveryIndex()).append(":").append(getBraveryValue(getBraveryIndex()));
out.append("\n\t Herd Mentality: ").append(getHerdMentalityIndex()).append(":").append(getHerdMentalityValue(getHerdMentalityIndex()));
out.append("\n\t Herd Mentality: ").append(getHerdMentalityIndex()).append(":")
.append(getHerdMentalityValue(getHerdMentalityIndex()));
out.append("\n\t Targets:");
out.append("\n\t\t Priority Coords: ");
for (final String t : getStrategicBuildingTargets()) {
Expand Down
Loading

0 comments on commit c8a471f

Please sign in to comment.