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

Facility implementation #2788

Merged
merged 12 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 7 additions & 0 deletions MekHQ/data/scenariomodifiers/HostileBVBudgetIncrease.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<AtBScenarioModifier>
<additionalBriefingText>Local coordination has allowed the opposition to deploy a larger force to respond to your presence.</additionalBriefingText>
<benefitsPlayer>fakse</benefitsPlayer>
Windchild292 marked this conversation as resolved.
Show resolved Hide resolved
<eventTiming>PreForceGeneration</eventTiming>
<eventRecipient>Opposing</eventRecipient>
<bvBudgetAdditiveMultiplier>-1</bvBudgetAdditiveMultiplier>
</AtBScenarioModifier>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<AtBScenarioModifier>
<additionalBriefingText>Improved coordination allows friendly reinforcements to deploy quicker.</additionalBriefingText>
<benefitsPlayer>true</benefitsPlayer>
<eventTiming>PreForceGeneration</eventTiming>
<eventRecipient>Allied</eventRecipient>
<reinforcementDelayReduction>1</reinforcementDelayReduction>
</AtBScenarioModifier>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<AtBScenarioModifier>
<additionalBriefingText>Improved coordination allows hostile reinforcements to deploy quicker.</additionalBriefingText>
<benefitsPlayer>false</benefitsPlayer>
<eventTiming>PreForceGeneration</eventTiming>
<eventRecipient>Opposing</eventRecipient>
<reinforcementDelayReduction>1</reinforcementDelayReduction>
</AtBScenarioModifier>
3 changes: 3 additions & 0 deletions MekHQ/data/scenariomodifiers/groundBattleModifiers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<modifier>
GoodEquipment.xml
</modifier>
<modifier>
HostileBVBudgetIncrease.xml
</modifier>
<!--modifier>
Need ability to allow player to specifically deploy dropships
HotDrop.xml
Expand Down
9 changes: 9 additions & 0 deletions MekHQ/data/scenariomodifiers/modifiermanifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<modifier>
GoodEquipment.xml
</modifier>
<modifier>
HostileBVBudgetIncrease.xml
</modifier>
<modifier>
BadEvent.xml
</modifier>
Expand Down Expand Up @@ -86,6 +89,12 @@
<modifier>
PiratesPresentGround.xml
</modifier>
<modifier>
ReinforcementDelayReductionHostile.xml
</modifier>
<modifier>
ReinforcementDelayReductionAllied.xml
</modifier>
<!--modifier>
Need "special duel flag".
Duel.xml
Expand Down
1 change: 1 addition & 0 deletions MekHQ/data/stratconfacilities/AlliedDataCenter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<displayableName>Data Center</displayableName>
<facilityType>DataCenter</facilityType>
<owner>Allied</owner>
<revealTrack>true</revealTrack>
<visible>true</visible>
</StratconFacility>
2 changes: 2 additions & 0 deletions MekHQ/data/stratconfacilities/AlliedEarlyWarningSystem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
<displayableName>Early Warning Center</displayableName>
<facilityType>EarlyWarningSystem</facilityType>
<owner>Allied</owner>
<localModifiers>ReinforcementDelayReductionAllied.xml</localModifiers>
<sharedModifiers>ReinforcementDelayReductionAllied.xml</sharedModifiers>
<visible>true</visible>
</StratconFacility>
1 change: 1 addition & 0 deletions MekHQ/data/stratconfacilities/AlliedOrbitalDefense.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<displayableName>Orbital Defense</displayableName>
<facilityType>OrbitalDefense</facilityType>
<owner>Allied</owner>
<preventAerospace>true</preventAerospace>
<visible>true</visible>
</StratconFacility>
1 change: 1 addition & 0 deletions MekHQ/data/stratconfacilities/AlliedSupplyDepot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<displayableName>Supply Depot</displayableName>
<facilityType>SupplyDepot</facilityType>
<owner>Allied</owner>
<weeklySPModifier>1</weeklySPModifier>
<visible>true</visible>
</StratconFacility>
1 change: 1 addition & 0 deletions MekHQ/data/stratconfacilities/HostileDataCenter.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<StratconFacility>
<scenarioOddsModifier>5</scenarioOddsModifier>
<capturedDefinition>AlliedDataCenter.xml</capturedDefinition>
<displayableName>Data Center</displayableName>
<facilityType>DataCenter</facilityType>
Expand Down
4 changes: 3 additions & 1 deletion MekHQ/data/stratconfacilities/HostileEarlyWarningSystem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<capturedDefinition>AlliedEarlyWarningSystem.xml</capturedDefinition>
<displayableName>Early Warning Center</displayableName>
<facilityType>EarlyWarningSystem</facilityType>
<owner>Allied</owner>
<owner>Opposing</owner>
<localModifiers>ReinforcementDelayReductionHostile.xml</localModifiers>
<sharedModifiers>ReinforcementDelayReductionHostile.xml</sharedModifiers>
<visible>true</visible>
</StratconFacility>
1 change: 1 addition & 0 deletions MekHQ/data/stratconfacilities/HostileOrbitalDefense.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<displayableName>Orbital Defense</displayableName>
<facilityType>OrbitalDefense</facilityType>
<owner>Opposing</owner>
<preventAerospace>true</preventAerospace>
<visible>false</visible>
</StratconFacility>
3 changes: 3 additions & 0 deletions MekHQ/data/stratconfacilities/HostileSupplyDepot.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<StratconFacility>
<bvBudgetModifier>0.05</bvBudgetModifier>
<capturedDefinition>AlliedSupplyDepot.xml</capturedDefinition>
<displayableName>Supply Depot</displayableName>
<localModifiers>HostileBVBudgetIncrease.xml</localModifiers>
<sharedModifiers>HostileBVBudgetIncrease.xml</sharedModifiers>
<facilityType>SupplyDepot</facilityType>
<owner>Opposing</owner>
<visible>false</visible>
Expand Down
41 changes: 30 additions & 11 deletions MekHQ/src/mekhq/campaign/mission/AtBDynamicScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ public static class BenchedEntityData {
private static final String PLAYER_UNIT_SWAP_TEMPLATE_ELEMENT = "Template";
private static final String PLAYER_UNIT_SWAP_ENTITY_ELEMENT = "entity";

// derived fields used for various calculations
private int effectivePlayerUnitCount;
private int effectivePlayerBV;
private double effectivePlayerUnitCountMultiplier;
private double effectivePlayerBVMultiplier;

private int friendlyReinforcementDelayReduction;
private int hostileReinforcementDelayReduction;

// derived fields used for various calculations
private int effectiveOpforSkill;
private int effectiveOpforQuality;

Expand Down Expand Up @@ -230,20 +233,20 @@ public void removeBotForce(int x) {
super.removeBotForce(x);
}

public int getEffectivePlayerUnitCount() {
return effectivePlayerUnitCount;
public double getEffectivePlayerUnitCountMultiplier() {
return effectivePlayerUnitCountMultiplier;
}

public void setEffectivePlayerUnitCount(int unitCount) {
effectivePlayerUnitCount = unitCount;
public void setEffectivePlayerUnitCountMultiplier(double multiplier) {
effectivePlayerUnitCountMultiplier = multiplier;
}

public int getEffectivePlayerBV() {
return effectivePlayerBV;
public double getEffectivePlayerBVMultiplier() {
return effectivePlayerBVMultiplier;
}

public void setEffectivePlayerBV(int unitCount) {
effectivePlayerBV = unitCount;
public void setEffectivePlayerBVMultiplier(double multiplier) {
effectivePlayerBVMultiplier = multiplier;
}

public void setScenarioTemplate(ScenarioTemplate template) {
Expand Down Expand Up @@ -294,6 +297,22 @@ public void setEffectiveOpforQuality(int qualityLevel) {
effectiveOpforQuality = qualityLevel;
}

public int getFriendlyReinforcementDelayReduction() {
return friendlyReinforcementDelayReduction;
}

public void setFriendlyReinforcementDelayReduction(int friendlyReinforcementDelayReduction) {
this.friendlyReinforcementDelayReduction = friendlyReinforcementDelayReduction;
}

public int getHostileReinforcementDelayReduction() {
return hostileReinforcementDelayReduction;
}

public void setHostileReinforcementDelayReduction(int hostileReinforcementDelayReduction) {
this.hostileReinforcementDelayReduction = hostileReinforcementDelayReduction;
}

/**
* This is used to indicate that player forces have been assigned to this scenario
* and that AtBDynamicScenarioFactory.finalizeScenario() has been called on this scenario to
Expand Down
23 changes: 16 additions & 7 deletions MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,9 @@ public static int calculateEffectiveBV(AtBDynamicScenario scenario, Campaign cam
bvBudget += forceBVBudget;
}
}

bvBudget += bvBudget * scenario.getEffectivePlayerBVMultiplier();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a Math.round, Math.floor, or Math.ceil

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It always produces a whole number.

Copy link
Contributor

@Windchild292 Windchild292 Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also an unrounded double to integer cast, and thus may not in future... and causes another CI issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure why we care if the bv budget drifts one way or the other by 1 point - we're usually talking thousands or tens of thousands of point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And honestly, how often does java change the behavior of their "double to integer" cast? It's not like we're directly executing CPU instructions here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rarely, and I know it is minor... but it's still a code scanning alert both in LGTM and in GitHub Actions, and I'm trying to keep the first low while reducing the latter.



// allied bot forces that contribute to BV do not get multiplied by the difficulty
// even if the player is super good, the AI doesn't get any better
Expand Down Expand Up @@ -1934,7 +1937,7 @@ private static void setDeploymentTurns(AtBDynamicScenario scenario) {
for (int x = 0; x < scenario.getNumBots(); x++) {
BotForce currentBotForce = scenario.getBotForce(x);
ScenarioForceTemplate forceTemplate = scenario.getBotForceTemplates().get(currentBotForce);
setDeploymentTurns(currentBotForce, forceTemplate.getArrivalTurn(), scenario);
setDeploymentTurns(currentBotForce, forceTemplate, scenario);
}
}

Expand All @@ -1945,18 +1948,24 @@ private static void setDeploymentTurns(AtBDynamicScenario scenario) {
* ARRIVAL_TURN_STAGGERED_BY_LANCE is not implemented.
* ARRIVAL_TURN_STAGGERED is processed just prior to scenario start instead (?)
*/
public static void setDeploymentTurns(BotForce botForce, int deployRound,
public static void setDeploymentTurns(BotForce botForce, ScenarioForceTemplate forceTemplate,
Windchild292 marked this conversation as resolved.
Show resolved Hide resolved
AtBDynamicScenario scenario) {
// deployment turns don't matter for transported entities
List<Entity> untransportedEntities = scenario.filterUntransportedUnits(botForce.getEntityList());

if (deployRound == ScenarioForceTemplate.ARRIVAL_TURN_STAGGERED_BY_LANCE) {
if (forceTemplate.getArrivalTurn() == ScenarioForceTemplate.ARRIVAL_TURN_STAGGERED_BY_LANCE) {
setDeploymentTurnsStaggeredByLance(untransportedEntities);
} else if (deployRound == ScenarioForceTemplate.ARRIVAL_TURN_AS_REINFORCEMENTS) {
setDeploymentTurnsForReinforcements(untransportedEntities, 0);
} else if (forceTemplate.getArrivalTurn() == ScenarioForceTemplate.ARRIVAL_TURN_AS_REINFORCEMENTS) {
if (forceTemplate.getForceAlignment() == ForceAlignment.Opposing.ordinal()) {
setDeploymentTurnsForReinforcements(untransportedEntities, scenario.getHostileReinforcementDelayReduction());
} else if (forceTemplate.getForceAlignment() != ForceAlignment.Third.ordinal()) {
setDeploymentTurnsForReinforcements(untransportedEntities, scenario.getFriendlyReinforcementDelayReduction());
} else {
setDeploymentTurnsForReinforcements(untransportedEntities, 0);
}
Windchild292 marked this conversation as resolved.
Show resolved Hide resolved
} else {
for (Entity entity : untransportedEntities) {
entity.setDeployRound(deployRound);
entity.setDeployRound(forceTemplate.getArrivalTurn());
}
}
}
Expand Down Expand Up @@ -1997,7 +2006,7 @@ public static void setPlayerDeploymentTurns(AtBDynamicScenario scenario, Campaig
if (deployRound == ScenarioForceTemplate.ARRIVAL_TURN_STAGGERED_BY_LANCE) {
setDeploymentTurnsStaggeredByLance(forceEntities);
} else if (deployRound == ScenarioForceTemplate.ARRIVAL_TURN_AS_REINFORCEMENTS) {
setDeploymentTurnsForReinforcements(forceEntities, strategy);
setDeploymentTurnsForReinforcements(forceEntities, strategy + scenario.getFriendlyReinforcementDelayReduction());
} else {
for (Entity entity : forceEntities) {
entity.setDeployRound(deployRound);
Expand Down
32 changes: 31 additions & 1 deletion MekHQ/src/mekhq/campaign/mission/atb/AtBScenarioModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public enum EventTiming {
private Boolean useAmbushLogic = null;
private Boolean switchSides = null;
private Integer numExtraEvents = null;
private Double bvBudgetAdditiveMultiplier = null;
private Integer reinforcementDelayReduction = null;
private List<ScenarioObjective> objectives = new ArrayList<>();

private Map<String, String> linkedModifiers = new HashMap<>();
Expand Down Expand Up @@ -392,7 +394,17 @@ public void processModifier(AtBDynamicScenario scenario, Campaign campaign, Even
}

if ((getNumExtraEvents() != null) && (getNumExtraEvents() > 0)) {
AtBScenarioModifierApplicator.applyExtraEvent(scenario, getEventRecipient() == ForceAlignment.Allied);
for (int x = 0; x < getNumExtraEvents(); x++) {
AtBScenarioModifierApplicator.applyExtraEvent(scenario, getEventRecipient() == ForceAlignment.Allied);
}
}

if (getBVBudgetAdditiveMultiplier() != null) {
scenario.setEffectivePlayerBVMultiplier(getBVBudgetAdditiveMultiplier());
}

if ((getReinforcementDelayReduction() != null) && (getEventRecipient() != null)) {
AtBScenarioModifierApplicator.applyReinforcementDelayReduction(scenario, eventRecipient, getReinforcementDelayReduction());
}
}
}
Expand Down Expand Up @@ -422,6 +434,8 @@ public AtBScenarioModifier clone() {
copy.useAmbushLogic = useAmbushLogic;
copy.linkedModifiers = linkedModifiers == null ? new HashMap<>() : new HashMap<>(linkedModifiers);
copy.objectives = objectives == null ? new ArrayList<>() : new ArrayList<>(objectives);
copy.bvBudgetAdditiveMultiplier = bvBudgetAdditiveMultiplier;
copy .reinforcementDelayReduction = reinforcementDelayReduction;
return copy;
}

Expand Down Expand Up @@ -561,6 +575,22 @@ public void setNumExtraEvents(Integer numExtraEvents) {
this.numExtraEvents = numExtraEvents;
}

public Double getBVBudgetAdditiveMultiplier() {
return bvBudgetAdditiveMultiplier;
}

public void setBVBudgetAdditiveMultiplier(Double bvBudgetAdditiveMultiplier) {
this.bvBudgetAdditiveMultiplier = bvBudgetAdditiveMultiplier;
}

public Integer getReinforcementDelayReduction() {
return reinforcementDelayReduction;
}

public void setReinforcementDelayReduction(Integer reinforcementDelayReduction) {
this.reinforcementDelayReduction = reinforcementDelayReduction;
}

/**
* Map containing string tuples:
* "Alternate" briefing description, name of file containing other modifiers associated with this one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void postAddForce(Campaign campaign, AtBDynamicScenario scenario,
// the most recently added bot force is the one we just generated
BotForce generatedBotForce = scenario.getBotForce(scenario.getNumBots() - 1);
generatedBotForce.setStart(deploymentZone);
AtBDynamicScenarioFactory.setDeploymentTurns(generatedBotForce, templateToApply.getArrivalTurn(), scenario);
AtBDynamicScenarioFactory.setDeploymentTurns(generatedBotForce, templateToApply, scenario);
AtBDynamicScenarioFactory.setDestinationZone(generatedBotForce, templateToApply);

// at this point, we have to re-translate the scenario objectives
Expand Down Expand Up @@ -342,4 +342,15 @@ public static void applyExtraEvent(AtBDynamicScenario scenario, boolean goodEven
scenario.addScenarioModifier(AtBScenarioModifier.getRandomBattleModifier(scenario.getTemplate().mapParameters.getMapLocation(),
(Boolean) goodEvent));
}

/**
* Applies a flat reduction to the reinforcement arrival times, either of player/allied forces or hostile forces.
*/
public static void applyReinforcementDelayReduction(AtBDynamicScenario scenario, ForceAlignment recipient, int value) {
if (recipient == ForceAlignment.Allied) {
scenario.setFriendlyReinforcementDelayReduction(value);
} else if (recipient == ForceAlignment.Opposing) {
scenario.setHostileReinforcementDelayReduction(value);
}
}
}
Loading