Skip to content

Commit 66390e1

Browse files
authored
Merge pull request #7277 from IllianiBird/outlawSystemAccess
Improvement: Optimized Outlaw System Access
2 parents e06d9ee + fc238b0 commit 66390e1

File tree

7 files changed

+50
-31
lines changed

7 files changed

+50
-31
lines changed

MekHQ/resources/mekhq/resources/ContractMarketDialog.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lblEmployer.text=Employer:
2424
lblEnemy.text=Enemy:
2525
lblMissionType.text=Mission Type:
2626
lblLocation.text=Location:
27-
lblDistance.text= Days (Jumps) to Location:
27+
lblDistance.text=Estimated Days (Jumps) to Location:
2828
lblAllyRating.text=Ally Experience & Equipment:
2929
lblEnemyRating.text=Enemy Experience & Equipment:
3030
lblStartDate.text=Start Date:

MekHQ/resources/mekhq/resources/ContractViewPanel.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ lblAllyRating.text=<html><nobr><b>Ally Experience & Equipment:</b></nobr></html>
1818
lblEnemyRating.text=<html><nobr><b>Enemy Experience & Equipment:</b></nobr></html>
1919
lblMorale.text=<html><nobr><b>Enemy Morale:</b></nobr></html>
2020
lblScore.text=<html><nobr><b>Contract Score:</b></nobr></html>
21-
lblDistance.text=<html><nobr><b>Days (Jumps) to Location:</b></nobr></html>
21+
lblDistance.text=<html><nobr><b>Estimated Days (Jumps) to Location:</b></nobr></html>
2222
lblOverhead.text=<html><nobr><b>Overhead Compensation:</b></nobr></html>
2323
lblSupport.text=<html><nobr><b>StraightSupport:</b></nobr></html>
2424
lblSharePct.text=<html><nobr><b>Shares:</b></nobr></html>

MekHQ/resources/mekhq/resources/NewContractDialog.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lblAllyRating.text=Ally Experience & Equipment:
3939
lblEnemyRating.text=Enemy Experience & Equipment:
4040
chkShowAllFactions.text=Show All Factions
4141
chkShowAllPlanets.text=Show All Planets
42-
lblDistance.text=Days (Jumps) to Location:
42+
lblDistance.text=Estimated Days (Jumps) to Location:
4343
lblAllyBotName.text=Ally Bot Name:
4444
lblEnemyBotName.text=Enemy Bot Name:
4545
lblAllyCamo.text=Ally Camo

MekHQ/src/mekhq/campaign/Campaign.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6993,6 +6993,23 @@ public Accountant getAccountant() {
69936993
return new Accountant(this);
69946994
}
69956995

6996+
/**
6997+
* Calculates and returns a {@code JumpPath} between two planetary systems, using default parameters for jump range
6998+
* and travel safety.
6999+
*
7000+
* <p>This method provides a convenient way to compute the most likely or optimal jump path from the specified
7001+
* starting system to the destination system. Internal behavior and constraints are determined by the method's
7002+
* default parameter settings.</p>
7003+
*
7004+
* @param start the starting {@link PlanetarySystem}
7005+
* @param end the destination {@link PlanetarySystem}
7006+
*
7007+
* @return the calculated {@link JumpPath} between the two systems
7008+
*/
7009+
public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
7010+
return calculateJumpPath(start, end, true, true);
7011+
}
7012+
69967013
/**
69977014
* Calculates the optimal jump path between two planetary systems using the A* algorithm.
69987015
*
@@ -7008,12 +7025,18 @@ public Accountant getAccountant() {
70087025
*
70097026
* @param start The starting planetary system
70107027
* @param end The destination planetary system
7028+
* @param skipAccessCheck {@code true} to skip checking for Outlaw status in system, {@code false} otherwise.
7029+
* Should be {@code false} when determining contract-related jump paths as
7030+
* system access is guaranteed for contract target systems.
7031+
* @param skipEmptySystemCheck {@code true} to skip checking for empty system status, {@code false} otherwise.
7032+
* Should be {@code false} when determining contract-related jump paths.
70117033
*
70127034
* @return A {@link JumpPath} containing the sequence of systems to traverse, or {@code null} if no valid path
70137035
* exists between the systems. If start and end are the same system, returns a path containing only that
70147036
* system.
70157037
*/
7016-
public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
7038+
public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end, boolean skipAccessCheck,
7039+
boolean skipEmptySystemCheck) {
70177040
// Handle edge cases
70187041
if (null == start) {
70197042
return new JumpPath();
@@ -7026,7 +7049,9 @@ public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
70267049
}
70277050

70287051
// Shortcuts to ensure we're not processing a lot of data when we're unable to reach the target system
7029-
if (isAvoidingEmptySystems && end.getPopulation(currentDay) == 0) {
7052+
if (!skipEmptySystemCheck
7053+
&& isAvoidingEmptySystems
7054+
&& end.getPopulation(currentDay) == 0) {
70307055
new ImmersiveDialogSimple(this, getSeniorAdminPerson(AdministratorSpecialization.TRANSPORT), null,
70317056
String.format(resources.getString("unableToEnterSystem.abandoned.ic"), getCommanderAddress(false)),
70327057
null, resources.getString("unableToEnterSystem.abandoned.ooc"), null, false);
@@ -7036,9 +7061,11 @@ public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
70367061

70377062
List<AtBContract> activeAtBContracts = getActiveAtBContracts();
70387063

7039-
if (campaignOptions.isUseFactionStandingOutlawed()) {
7064+
if (!skipAccessCheck
7065+
&& campaignOptions.isUseFactionStandingOutlawedSafe()) {
7066+
FactionHints factionHints = FactionHints.defaultFactionHints();
70407067
boolean canAccessSystem = FactionStandingUtilities.canEnterTargetSystem(faction, factionStandings,
7041-
getCurrentSystem(), end, currentDay, activeAtBContracts);
7068+
getCurrentSystem(), end, currentDay, activeAtBContracts, factionHints);
70427069
if (!canAccessSystem) {
70437070
new ImmersiveDialogSimple(this, getSeniorAdminPerson(AdministratorSpecialization.TRANSPORT), null,
70447071
String.format(resources.getString("unableToEnterSystem.outlawed.ic"), getCommanderAddress(false)),
@@ -7072,6 +7099,8 @@ public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
70727099
scoreG.put(current, 0.0);
70737100
closed.add(current);
70747101

7102+
FactionHints factionHints = FactionHints.defaultFactionHints();
7103+
70757104
// A* search
70767105
final int MAX_JUMPS = 10000;
70777106
for (int jumps = 0; jumps < MAX_JUMPS; jumps++) {
@@ -7095,9 +7124,10 @@ public JumpPath calculateJumpPath(PlanetarySystem start, PlanetarySystem end) {
70957124
}
70967125

70977126
// Skip systems where the campaign is outlawed
7098-
if (campaignOptions.isUseFactionStandingOutlawed()) {
7127+
if (!skipAccessCheck
7128+
&& campaignOptions.isUseFactionStandingOutlawed()) {
70997129
boolean canAccessSystem = FactionStandingUtilities.canEnterTargetSystem(faction, factionStandings,
7100-
getCurrentSystem(), neighborSystem, currentDay, activeAtBContracts);
7130+
getCurrentSystem(), neighborSystem, currentDay, activeAtBContracts, factionHints);
71017131
if (!canAccessSystem) {
71027132
return;
71037133
}

MekHQ/src/mekhq/campaign/universe/factionStanding/FactionStandingUtilities.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
*/
3333
package mekhq.campaign.universe.factionStanding;
3434

35-
import java.util.List;
36-
3735
import java.time.LocalDate;
3836
import java.util.HashSet;
37+
import java.util.List;
3938
import java.util.Set;
4039

4140
import megamek.common.annotations.Nullable;
@@ -363,7 +362,6 @@ public static boolean isUseCommandCircuit(boolean overridingCommandCircuitRequir
363362
* currentSystem} is {@code null}).</li>
364363
* <li>If the player is outlawed in the target system, entry is denied.</li>
365364
* <li>If the campaign faction is at war with all system factions, entry is denied.</li>
366-
* <li>If all system factions are at war with any employer faction, entry is denied.</li>
367365
* <li>If none of the above conditions block entry, it is permitted.</li>
368366
* </ol>
369367
*
@@ -373,6 +371,7 @@ public static boolean isUseCommandCircuit(boolean overridingCommandCircuitRequir
373371
* @param targetSystem the planetary system to test entry for
374372
* @param when the date of attempted entry (population/ownership may change over time)
375373
* @param activeAtBContracts list of currently active contracts
374+
* @param factionHints the details of the current factional relations
376375
*
377376
* @return {@code true} if entry to the target system is allowed; {@code false} otherwise
378377
*
@@ -381,7 +380,7 @@ public static boolean isUseCommandCircuit(boolean overridingCommandCircuitRequir
381380
*/
382381
public static boolean canEnterTargetSystem(Faction campaignFaction, FactionStandings factionStandings,
383382
@Nullable PlanetarySystem currentSystem, PlanetarySystem targetSystem, LocalDate when,
384-
List<AtBContract> activeAtBContracts) {
383+
List<AtBContract> activeAtBContracts, FactionHints factionHints) {
385384
// Always allowed in empty systems
386385
if (targetSystem.getPopulation(when) == 0) {
387386
LOGGER.debug("Target system is empty, access granted");
@@ -420,7 +419,6 @@ public static boolean canEnterTargetSystem(Faction campaignFaction, FactionStand
420419
}
421420

422421
// Disallow if the campaign faction is at war with all system factions
423-
FactionHints factionHints = FactionHints.defaultFactionHints();
424422
boolean allAtWarWithCampaign = systemFactions
425423
.stream()
426424
.allMatch(systemFaction -> factionHints.isAtWarWith(campaignFaction,
@@ -431,19 +429,6 @@ public static boolean canEnterTargetSystem(Faction campaignFaction, FactionStand
431429
return false;
432430
}
433431

434-
// Disallow if all system factions are at war with any one employer
435-
for (Faction employer : contractEmployers) {
436-
boolean allAtWarWithEmployer = systemFactions
437-
.stream()
438-
.allMatch(systemFaction -> factionHints.getCurrentWar(employer,
439-
systemFaction,
440-
when) != null);
441-
if (allAtWarWithEmployer) {
442-
LOGGER.debug("All system factions are at war with employer {}, access denied", employer.getShortName());
443-
return false;
444-
}
445-
}
446-
447432
LOGGER.debug("Access granted");
448433
return true;
449434
}

MekHQ/src/mekhq/gui/InterstellarMapPanel.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import mekhq.campaign.JumpPath;
7474
import mekhq.campaign.mission.AtBContract;
7575
import mekhq.campaign.universe.Faction;
76+
import mekhq.campaign.universe.FactionHints;
7677
import mekhq.campaign.universe.Factions;
7778
import mekhq.campaign.universe.PlanetarySystem;
7879
import mekhq.campaign.universe.SocioIndustrialData;
@@ -369,7 +370,7 @@ public void mouseClicked(MouseEvent e) {
369370
if (e.isAltDown()) {
370371
// calculate a new jump path from the current location
371372
jumpPath = InterstellarMapPanel.this.campaign.calculateJumpPath(InterstellarMapPanel.this.campaign.getCurrentSystem(),
372-
target);
373+
target, false, false);
373374
selectedSystem = target;
374375
repaint();
375376
notifyListeners();
@@ -380,7 +381,8 @@ public void mouseClicked(MouseEvent e) {
380381
if (null == lastSystem) {
381382
lastSystem = InterstellarMapPanel.this.campaign.getCurrentSystem();
382383
}
383-
JumpPath addPath = InterstellarMapPanel.this.campaign.calculateJumpPath(lastSystem, target);
384+
JumpPath addPath = InterstellarMapPanel.this.campaign.calculateJumpPath(lastSystem,
385+
target, false, false);
384386
if (!jumpPath.isEmpty()) {
385387
addPath.removeFirstSystem();
386388
}
@@ -734,6 +736,8 @@ protected void paintComponent(Graphics g) {
734736
LocalDate today = campaign.getLocalDate();
735737
List<AtBContract> activeAtBContracts = campaign.getActiveAtBContracts();
736738

739+
FactionHints factionHints = FactionHints.defaultFactionHints();
740+
737741
for (PlanetarySystem system : systems) {
738742
if (isSystemVisible(system, false)) {
739743
double x = map2scrX(system.getX());
@@ -822,7 +826,7 @@ protected void paintComponent(Graphics g) {
822826
// Outlaw status image
823827
if (isUseFactionStandingOutlawing) {
824828
boolean isOutlawedInSystem = !FactionStandingUtilities.canEnterTargetSystem(campaignFaction,
825-
factionStandings, null, system, today, activeAtBContracts);
829+
factionStandings, null, system, today, activeAtBContracts, factionHints);
826830
if (isOutlawedInSystem) {
827831
int half = (int) (size * 0.8);
828832
g2.setPaint(Color.BLACK);

MekHQ/src/mekhq/gui/MapTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void refreshAll() {
255255
private void calculateJumpPath() {
256256
if (null != panMap.getSelectedSystem()) {
257257
panMap.setJumpPath(getCampaign().calculateJumpPath(getCampaign().getCurrentSystem(),
258-
panMap.getSelectedSystem()));
258+
panMap.getSelectedSystem(), false, false));
259259
refreshPlanetView();
260260
}
261261
}

0 commit comments

Comments
 (0)