Fix alliance offer cooldown tracking (#8703)

This commit is contained in:
2026-07-18 08:44:42 -07:00
committed by GitHub
parent 3dce099b2a
commit 14a475032e
3 changed files with 54 additions and 4 deletions
@@ -72,7 +72,7 @@ object TrustForDiplomacy {
): Boolean =
!gameState
.factions(actingFactionId)
.lastOutgoingTruceOfferRounds
.lastOutgoingAllianceOfferRounds
.exists {
case OutgoingOfferRound(toFactionId, roundId) =>
toFactionId == targetFactionId && roundId + MinimumMonthsBeforeRepeatTruceOffer.intValue > gameState.currentRoundId
@@ -2,7 +2,7 @@ package net.eagle0.eagle.library.util.command_choice_helpers.quest_command_selec
import net.eagle0.common.SeededRandom
import net.eagle0.eagle.{FactionId, HeroId}
import net.eagle0.eagle.library.settings.MinimumTrustToOfferAlliance
import net.eagle0.eagle.library.settings.{MinimumMonthsBeforeRepeatTruceOffer, MinimumTrustToOfferAlliance}
import net.eagle0.eagle.library.util.CommandSelection
import net.eagle0.eagle.model.state.{GameType, RoundPhase}
import net.eagle0.eagle.model.state.command.available.AvailableCommand
@@ -12,6 +12,7 @@ import net.eagle0.eagle.model.state.command.selected.SelectedCommand.DiplomacySe
import net.eagle0.eagle.model.state.faction.concrete.FactionC
import net.eagle0.eagle.model.state.faction.FactionRelationship
import net.eagle0.eagle.model.state.faction.FactionRelationship.RelationshipLevel.{Ally, Hostile}
import net.eagle0.eagle.model.state.faction.FactionT.OutgoingOfferRound
import net.eagle0.eagle.model.state.game_state.GameState
import net.eagle0.eagle.model.state.hero.concrete.HeroC
import net.eagle0.eagle.model.state.quest.AllianceQuest
@@ -39,6 +40,9 @@ class AllianceQuestCommandChooserTest extends AnyFlatSpec with BeforeAndAfterEac
trustValue = 30
)
),
currentRoundId: Int = 1,
lastOutgoingTruceOfferRounds: Vector[OutgoingOfferRound] = Vector.empty,
lastOutgoingAllianceOfferRounds: Vector[OutgoingOfferRound] = Vector.empty,
targetFid1Relationships: Vector[FactionRelationship] = Vector.empty,
targetFid2Relationships: Vector[FactionRelationship] = Vector.empty
): GameState = {
@@ -47,7 +51,9 @@ class AllianceQuestCommandChooserTest extends AnyFlatSpec with BeforeAndAfterEac
factionHeadId = 0,
name = "Acting Faction",
leaderIds = Vector.empty,
factionRelationships = actingFactionRelationships
factionRelationships = actingFactionRelationships,
lastOutgoingTruceOfferRounds = lastOutgoingTruceOfferRounds,
lastOutgoingAllianceOfferRounds = lastOutgoingAllianceOfferRounds
)
val targetFaction1 = FactionC(
id = targetFid1,
@@ -65,7 +71,7 @@ class AllianceQuestCommandChooserTest extends AnyFlatSpec with BeforeAndAfterEac
)
GameState(
gameId = 1,
currentRoundId = 1,
currentRoundId = currentRoundId,
currentPhase = RoundPhase.PlayerCommands,
currentDate =
net.eagle0.eagle.model.state.date.Date(year = 0, month = net.eagle0.eagle.model.state.date.Date.Month.January),
@@ -130,6 +136,7 @@ class AllianceQuestCommandChooserTest extends AnyFlatSpec with BeforeAndAfterEac
super.beforeEach()
MinimumTrustToOfferAlliance.setIntValue(25)
MinimumMonthsBeforeRepeatTruceOffer.setIntValue(6)
}
"AllianceQuestCommandChooser" should "return a command for an unaffiliated hero with that quest" in {
@@ -274,4 +281,46 @@ class AllianceQuestCommandChooserTest extends AnyFlatSpec with BeforeAndAfterEac
result.newValue.shouldBe(None)
}
it should "not repeat an alliance offer before the cooldown expires" in {
val result = AllianceQuestCommandChooser.chosenCommand(
actingFactionId = actingFid,
gameState = createGameState(
currentRoundId = 10,
lastOutgoingAllianceOfferRounds = Vector(
OutgoingOfferRound(toFactionId = targetFid1, roundId = 9),
OutgoingOfferRound(toFactionId = targetFid2, roundId = 9)
)
),
availableCommands = availableCommands,
uhsWithQuests = uhsWithQuests,
functionalRandom = SeededRandom(1976L)
)
result.newValue shouldBe None
}
it should "not suppress an alliance offer because of a recent truce offer" in {
val result = AllianceQuestCommandChooser.chosenCommand(
actingFactionId = actingFid,
gameState = createGameState(
currentRoundId = 10,
lastOutgoingTruceOfferRounds = Vector(
OutgoingOfferRound(toFactionId = targetFid1, roundId = 9)
)
),
availableCommands = availableCommands,
uhsWithQuests = uhsWithQuests,
functionalRandom = SeededRandom(1976L)
)
inside(result.newValue) {
case Some(command) =>
inside(command.selected) {
case selected: DiplomacySelected =>
selected.targetFactionId shouldBe targetFid1
selected.selectedOption shouldBe DiplomacyOptionType.Alliance
}
}
}
}
@@ -6,6 +6,7 @@ scala_test(
deps = [
"//src/main/scala/net/eagle0/common:functional_random",
"//src/main/scala/net/eagle0/eagle:eagle_pkg",
"//src/main/scala/net/eagle0/eagle/library/settings:minimum_months_before_repeat_truce_offer",
"//src/main/scala/net/eagle0/eagle/library/settings:minimum_trust_to_offer_alliance",
"//src/main/scala/net/eagle0/eagle/library/util:command_selection",
"//src/main/scala/net/eagle0/eagle/library/util/command_choice_helpers/quest_command_selectors:alliance_quest_command_chooser",