Skip to content

Commit

Permalink
feat: it seems to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Dec 2, 2024
1 parent 1d29545 commit b1bb1a6
Show file tree
Hide file tree
Showing 19 changed files with 467 additions and 620 deletions.
Binary file removed MekHQ/data/images/force/Units/Battle Magic.png
Binary file not shown.
493 changes: 76 additions & 417 deletions MekHQ/mmconf/defaultKeyBinds.xml

Large diffs are not rendered by default.

122 changes: 52 additions & 70 deletions MekHQ/mmconf/princessBehaviors.xml
Original file line number Diff line number Diff line change
@@ -1,73 +1,55 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<princessBehaviors>
<behavior>
<name>Valkiries:AI</name>
<destinationEdge>NONE</destinationEdge>
<retreatEdge>NEAREST</retreatEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>3</fallShameIndex>
<hyperAggressionIndex>6</hyperAggressionIndex>
<selfPreservationIndex>3</selfPreservationIndex>
<herdMentalityIndex>7</herdMentalityIndex>
<braveryIndex>8</braveryIndex>
<strategicBuildingTargets/>
</behavior>
<behavior>
<name>BERSERK</name>
<destinationEdge>NONE</destinationEdge>
<retreatEdge>NEAREST</retreatEdge>
<forcedWithdrawal>false</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>2</fallShameIndex>
<hyperAggressionIndex>10</hyperAggressionIndex>
<selfPreservationIndex>2</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>9</braveryIndex>
<strategicBuildingTargets/>
</behavior>
<behavior>
<name>DEFAULT</name>
<destinationEdge>NONE</destinationEdge>
<retreatEdge>NEAREST</retreatEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>5</fallShameIndex>
<hyperAggressionIndex>5</hyperAggressionIndex>
<selfPreservationIndex>5</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>5</braveryIndex>
<strategicBuildingTargets/>
</behavior>
<behavior>
<name>ESCAPE</name>
<destinationEdge>NONE</destinationEdge>
<retreatEdge>NEAREST</retreatEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>true</autoFlee>
<fallShameIndex>7</fallShameIndex>
<hyperAggressionIndex>1</hyperAggressionIndex>
<selfPreservationIndex>10</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>2</braveryIndex>
<strategicBuildingTargets/>
</behavior>
<behavior>
<name>COWARDLY</name>
<destinationEdge>NONE</destinationEdge>
<retreatEdge>NEAREST</retreatEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>8</fallShameIndex>
<hyperAggressionIndex>1</hyperAggressionIndex>
<selfPreservationIndex>10</selfPreservationIndex>
<herdMentalityIndex>8</herdMentalityIndex>
<braveryIndex>2</braveryIndex>
<strategicBuildingTargets/>
</behavior>
<behavior>
<name>COWARDLY</name>
<homeEdge>0</homeEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>8</fallShameIndex>
<hyperAggressionIndex>1</hyperAggressionIndex>
<selfPreservationIndex>10</selfPreservationIndex>
<herdMentalityIndex>8</herdMentalityIndex>
<braveryIndex>2</braveryIndex>
<strategicTargets />
</behavior>
<behavior>
<name>BERSERK</name>
<homeEdge>0</homeEdge>
<forcedWithdrawal>false</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>2</fallShameIndex>
<hyperAggressionIndex>10</hyperAggressionIndex>
<selfPreservationIndex>2</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>9</braveryIndex>
<strategicTargets />
</behavior>
<behavior>
<name>ESCAPE</name>
<homeEdge>0</homeEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>true</goHome>
<autoFlee>true</autoFlee>
<fallShameIndex>7</fallShameIndex>
<hyperAggressionIndex>1</hyperAggressionIndex>
<selfPreservationIndex>10</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>2</braveryIndex>
<strategicTargets />
</behavior>
<behavior>
<name>DEFAULT</name>
<homeEdge>0</homeEdge>
<forcedWithdrawal>true</forcedWithdrawal>
<goHome>false</goHome>
<autoFlee>false</autoFlee>
<fallShameIndex>5</fallShameIndex>
<hyperAggressionIndex>5</hyperAggressionIndex>
<selfPreservationIndex>5</selfPreservationIndex>
<herdMentalityIndex>5</herdMentalityIndex>
<braveryIndex>5</braveryIndex>
<strategicTargets />
</behavior>
</princessBehaviors>
15 changes: 15 additions & 0 deletions MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import mekhq.campaign.ResolveScenarioTracker;
import mekhq.campaign.ResolveScenarioTracker.PersonStatus;
import mekhq.campaign.autoResolve.AutoResolveEngine;
import mekhq.campaign.autoResolve.AutoResolveGame;
import mekhq.campaign.autoResolve.AutoResolveMethod;
import mekhq.campaign.autoResolve.helper.AutoResolveClient;
import mekhq.campaign.autoResolve.scenarioResolver.components.AutoResolveConcludedEvent;
Expand Down Expand Up @@ -542,6 +543,20 @@ public void autoResolveConcluded(AutoResolveConcludedEvent autoResolveConcludedE
new ResolveScenarioWizardDialog(campaignGUI.getFrame(),
true, tracker);
resolveDialog.setVisible(true);
if (resolveDialog.wasAborted()) {
for (UUID personId : tracker.getPeopleStatus().keySet()) {
Person person = getCampaign().getPerson(personId);
// person.setStatus(PersonnelStatus.ACTIVE);
person.setHits(person.getHitsPrior());
}
for (Unit unit : ((AutoResolveGame) autoResolveConcludedEvent.getGame()).getUnits()) {
var entity = unit.getEntity();

}
// should I do something here? Maybe do the trigger?
// MekHQ.triggerEvent(new ScenarioResolvedEvent(currentScenario));
return;
}

if (!getCampaign().getRetirementDefectionTracker().getRetirees().isEmpty()) {
RetirementDefectionDialog rdd = new RetirementDefectionDialog(campaignGUI,
Expand Down
3 changes: 2 additions & 1 deletion MekHQ/src/mekhq/campaign/ai/utility/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public Optional<Object> get(String key) {
return Optional.ofNullable(memory.getOrDefault(key, null));
}

@SuppressWarnings("unchecked")
public List<Map<String, Object>> getMemories(String key) {
return (List<Map<String, Object>>) memory.getOrDefault(key, new ArrayList<Map<String, Object>>());
return (List<Map<String, Object>>) memory.computeIfAbsent(key, k -> new ArrayList<Map<String, Object>>());
}

public boolean containsKey(String key) {
Expand Down
72 changes: 33 additions & 39 deletions MekHQ/src/mekhq/campaign/autoResolve/AutoResolveGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
import megamek.server.victory.VictoryResult;
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.autoResolve.damageHandler.CrewMustSurvive;
import mekhq.campaign.autoResolve.damageHandler.DamageHandlerChooser;
import mekhq.campaign.autoResolve.damageHandler.EntityMustSurvive;
import mekhq.campaign.autoResolve.scenarioResolver.abstractCombatSystem.actions.AcsActionHandler;
import mekhq.campaign.autoResolve.scenarioResolver.abstractCombatSystem.components.AcsFormation;
import mekhq.campaign.autoResolve.scenarioResolver.abstractCombatSystem.components.AcsFormationTurn;
import mekhq.campaign.autoResolve.scenarioResolver.abstractCombatSystem.components.AcsTurn;
import mekhq.campaign.mission.AtBScenario;
import mekhq.campaign.mission.ScenarioObjective;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.unit.Unit;

import java.util.*;
Expand All @@ -53,7 +57,7 @@ public class AutoResolveGame extends AbstractGame implements PlanetaryConditions
private final Campaign campaign;
private final List<Unit> units;
private final AtBScenario scenario;

private final List<String> forceMustBePreserved = new ArrayList<>();
/**
* Game Phase and rules
*/
Expand All @@ -68,8 +72,6 @@ public class AutoResolveGame extends AbstractGame implements PlanetaryConditions
*/
private final List<AcsTurn> turnList = new ArrayList<>();

private boolean gameEnded = false;

/**
* Tools for the game
*/
Expand All @@ -85,14 +87,22 @@ public class AutoResolveGame extends AbstractGame implements PlanetaryConditions
private final VictoryHelper victoryHelper = new VictoryHelper(this);
private int victoryPlayerId = Player.PLAYER_NONE;
private int victoryTeam = Player.TEAM_NONE;
private Player localPlayer;

public AutoResolveGame(MekHQ app, List<Unit> units, AtBScenario scenario) {
setBoard(0, new Board());
this.campaign = app.getCampaign();
this.localPlayer = campaign.getPlayer();
this.units = units;
this.scenario = scenario;
this.setupScenarioObjectives();
}

private void setupScenarioObjectives() {
forceMustBePreserved.clear();
scenario.getScenarioObjectives().forEach(objective -> {
if (objective.getObjectiveCriterion().equals(ScenarioObjective.ObjectiveCriterion.Preserve)) {
forceMustBePreserved.addAll(objective.getAssociatedForceNames());
}
});
}

public MapSettings getMapSettings() {
Expand Down Expand Up @@ -202,50 +212,22 @@ public Optional<Entity> getEntity(final int id) {
}

public void addEntity(Entity entity) {
// entity.setGame(this); Cant set the game!
if (entity instanceof Mek) {
((Mek) entity).setBAGrabBars();
((Mek) entity).setProtoMekClampMounts();
} else if (entity instanceof Tank) {
((Tank) entity).setBAGrabBars();
((Tank) entity).setTrailerHitches();
}

// Add magnetic clamp mounts
if ((entity instanceof Mek) && !entity.isOmni() && !entity.hasBattleArmorHandles()) {
entity.addTransporter(new ClampMountMek());
} else if ((entity instanceof Tank) && !entity.isOmni()
&& !entity.hasBattleArmorHandles()) {
entity.addTransporter(new ClampMountTank());
}

entity.setGameOptions();
if (entity.getC3UUIDAsString() == null) {
// We don't want to be resetting a UUID that exists already!
entity.setC3UUID();
}
// Add this Entity, ensuring that its id is unique
int id = entity.getId();
if (isIdUsed(id)) {
id = getNextEntityId();
entity.setId(id);
}
inGameObjects.put(id, entity);

if (id > lastEntityId) {
lastEntityId = id;
}

if (entity instanceof Mek mek) {
if (getOptions().booleanOption(OptionsConstants.RPG_CONDITIONAL_EJECTION)) {
mek.setAutoEject(true);
mek.setCondEjectAmmo(!entity.hasCase() && !entity.hasCASEII());
mek.setCondEjectEngine(true);
mek.setCondEjectCTDest(true);
mek.setCondEjectHeadshot(true);
} else {
mek.setAutoEject(!entity.hasCase() && !entity.hasCASEII());
}
mek.setAutoEject(true);
mek.setCondEjectAmmo(!entity.hasCase() && !entity.hasCASEII());
mek.setCondEjectEngine(true);
mek.setCondEjectCTDest(true);
mek.setCondEjectHeadshot(true);
}

entity.setInitialBV(entity.calculateBattleValue(false, false));
Expand Down Expand Up @@ -711,6 +693,18 @@ public void damageEntity(Entity entity, int removalCondition) {
default -> entity.getTotalOArmor() * 0.33;
};
var numberOfDices = (int) (targetDamage / 6 / 0.6);
DamageHandlerChooser.chooseHandler(entity).applyDamageInClusters(Compute.d6(numberOfDices), Compute.d6());
var damage = Compute.d6(numberOfDices);
var clusterSize = 5;

var retreating = removalCondition == IEntityRemovalConditions.REMOVE_IN_RETREAT;
var captured = removalCondition == IEntityRemovalConditions.REMOVE_CAPTURED;
var ejected = removalCondition == IEntityRemovalConditions.REMOVE_EJECTED;
var devastated = removalCondition == IEntityRemovalConditions.REMOVE_DEVASTATED;

var crewMustSurvive = (retreating || captured || ejected) ? CrewMustSurvive.YES : CrewMustSurvive.NO;
var entityMustSurvive = devastated ? EntityMustSurvive.NO : EntityMustSurvive.YES;

DamageHandlerChooser.chooseHandler(entity, crewMustSurvive, entityMustSurvive)
.applyDamageInClusters(damage, clusterSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import megamek.common.Aero;
import megamek.common.HitData;
import megamek.common.IEntityRemovalConditions;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -12,17 +13,31 @@
public class AeroDamageHandler implements DamageHandler<Aero> {

private final Aero entity;
private final Random random = new Random();
private final CrewMustSurvive crewMustSurvive;
private final EntityMustSurvive entityMustSurvive;

public AeroDamageHandler(Aero entity) {
public AeroDamageHandler(Aero entity, CrewMustSurvive crewMustSurvive, EntityMustSurvive entityMustSurvive) {
this.entity = entity;
this.crewMustSurvive = crewMustSurvive;
this.entityMustSurvive = entityMustSurvive;
}

@Override
public Aero entity() {
return entity;
}

@Override
public CrewMustSurvive crewMustSurvive() {
return crewMustSurvive;
}

@Override
public EntityMustSurvive entityMustSurvive() {
return entityMustSurvive;
}


@Override
public int getHitLocation() {
var entity = entity();
Expand All @@ -39,6 +54,12 @@ public int getHitLocation() {
return validLocations.isEmpty() ? -1 : validLocations.get(randomInt(validLocations.size()));
}

@Override
public void destroyLocationAfterEjection() {
entity().setDestroyed(true);
entity().setRemovalCondition(IEntityRemovalConditions.REMOVE_DEVASTATED);
}

@Override
public void damageInternals(HitDetails hitDetails) {
HitData hit = hitDetails.hit();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mekhq.campaign.autoResolve.damageHandler;
public enum CrewMustSurvive {
YES,
NO
}
Loading

0 comments on commit b1bb1a6

Please sign in to comment.