Skip to content

Issue 6560: Fix for negative temporary prisoner capacity #6567

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -6407,7 +6407,7 @@ public int getTemporaryPrisonerCapacity() {
}

public void setTemporaryPrisonerCapacity(int temporaryPrisonerCapacity) {
this.temporaryPrisonerCapacity = temporaryPrisonerCapacity;
this.temporaryPrisonerCapacity = max(PrisonerEventManager.MINIMUM_TEMPORARY_CAPACITY, temporaryPrisonerCapacity);
}

public RandomEventLibraries getRandomEventLibraries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package mekhq.campaign.randomEvents.prisoners;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
Expand Down Expand Up @@ -91,6 +92,9 @@ public class PrisonerEventManager {
private final int RESPONSE_TARGET_NUMBER = 7;

public static final int DEFAULT_TEMPORARY_CAPACITY = 100;
// The temporary prisoner capacity should never go below 0.
// But the security forces should be able to guard some prisoners in all cases
public static final int MINIMUM_TEMPORARY_CAPACITY = 25;
public static final double TEMPORARY_CAPACITY_DEGRADE_RATE = 0.1;

// These values are based on CamOps. CamOps states a squad of CI or one squad of BA can
Expand Down Expand Up @@ -175,7 +179,8 @@ int degradeTemporaryCapacity() {
int newCapacity = 0;

if (temporaryCapacityModifier != DEFAULT_TEMPORARY_CAPACITY) {
int degreeOfChange = (int) round(temporaryCapacityModifier * TEMPORARY_CAPACITY_DEGRADE_RATE);
double differendInTemporaryCapacity = (double) abs(DEFAULT_TEMPORARY_CAPACITY-temporaryCapacityModifier);
int degreeOfChange = max(1,(int) round(differendInTemporaryCapacity * TEMPORARY_CAPACITY_DEGRADE_RATE));

if (temporaryCapacityModifier < DEFAULT_TEMPORARY_CAPACITY) {
temporaryCapacityModifier += degreeOfChange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
*/
package mekhq.campaign.randomEvents.prisoners;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
import static mekhq.campaign.mission.enums.AtBMoraleLevel.STALEMATE;
import static mekhq.campaign.randomEvents.prisoners.PrisonerEventManager.DEFAULT_TEMPORARY_CAPACITY;
import static mekhq.campaign.randomEvents.prisoners.PrisonerEventManager.TEMPORARY_CAPACITY_DEGRADE_RATE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -78,11 +80,13 @@ void testDegradeTemporaryCapacity_DegradeDownTowardsDefault() {
// Act
int actualValue = eventManager.degradeTemporaryCapacity();

int degreeOfChange = (int) round(INITIAL_TEMPORARY_CAPACITY * TEMPORARY_CAPACITY_DEGRADE_RATE);
int differendInTemporaryCapacity = abs(DEFAULT_TEMPORARY_CAPACITY-INITIAL_TEMPORARY_CAPACITY);
int degreeOfChange = (int) max(1,round(differendInTemporaryCapacity * TEMPORARY_CAPACITY_DEGRADE_RATE));
int expectedValue = max(DEFAULT_TEMPORARY_CAPACITY, INITIAL_TEMPORARY_CAPACITY - degreeOfChange);

// Assert
assertEquals(expectedValue, actualValue);
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
}

@Test
Expand All @@ -107,6 +111,7 @@ void testDegradeTemporaryCapacity_DegradeDownTowardsDefault_ResultBelowDefault()

// Assert
assertEquals(expectedValue, actualValue);
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
}

@Test
Expand All @@ -128,11 +133,13 @@ void testDegradeTemporaryCapacity_DegradeUpTowardsDefault() {
// Act
int actualValue = eventManager.degradeTemporaryCapacity();

int degreeOfChange = (int) round(INITIAL_TEMPORARY_CAPACITY * TEMPORARY_CAPACITY_DEGRADE_RATE);
int differendInTemporaryCapacity = abs(DEFAULT_TEMPORARY_CAPACITY-INITIAL_TEMPORARY_CAPACITY);
int degreeOfChange = (int) max(1,round(differendInTemporaryCapacity * TEMPORARY_CAPACITY_DEGRADE_RATE));
int expectedValue = min(DEFAULT_TEMPORARY_CAPACITY, INITIAL_TEMPORARY_CAPACITY + degreeOfChange);

// Assert
assertEquals(expectedValue, actualValue);
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
}

@Test
Expand All @@ -157,6 +164,7 @@ void testDegradeTemporaryCapacity_DegradeUpTowardsDefault_ResultAboveDefault() {

// Assert
assertEquals(expectedValue, actualValue);
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
}

@Test
Expand Down
Loading