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

Cancel the chain reaction of defense pact #12703

Merged
merged 2 commits into from
Dec 25, 2024
Merged

Conversation

czyh2022
Copy link
Contributor

@czyh2022 czyh2022 commented Dec 24, 2024

I noticed the discussion in Discord about whether to cancel the chain reaction of defense pact. Based on this, I made some corresponding changes. Before a civilization calls a defense pact ally, it will check the Type of the war it is participating in. If it is already a DefensivePactWar, it will not continue to call allies.
Resolves #12564

…ct with other civilizations will no longer be chained.
.map { it.otherCiv() })

// Defensive pact chains are not allowed now
var listIndex = 0
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason to have this by index instead of 'for civ in othercovdefensivepactlist'?
I know this was here before you, but if we can improve readability, why not :)

Copy link
Collaborator

@SeventhM SeventhM Dec 24, 2024

Choose a reason for hiding this comment

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

Is there a reason we're doing indexing at all on a list and not using for ((index, civ) in otherCivDefensivePactList.withIndexed())? Like, "withIndexed" is explicitly in the Kotlin library so we don't need to do while loops for this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems to me there was - the list was modified within the loop

Copy link
Owner

Choose a reason for hiding this comment

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

Correct, but now it is no longer modified, so we can move to the more readable format
We don't even use the index anymore, just the civ

Comment on lines 292 to 300
/*
// Add their defensive pact allies
otherCivDefensivePactList.addAll(otherCivDefensivePactList[listIndex].diplomacy.values
.filter { diploChain -> diploChain.diplomaticStatus == DiplomaticStatus.DefensivePact
&& !otherCivDefensivePactList.contains(diploChain.otherCiv())
&& diploChain.otherCiv() != viewingCiv && diploChain.otherCiv() != otherCiv
&& !diploChain.otherCiv().isAtWarWith(viewingCiv) }
.map { it.otherCiv() })
*/
Copy link
Owner

Choose a reason for hiding this comment

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

Also delete this, there's no reason to have dead code in comments, if we want it we can get it back from git :)

Simplify the loop and delete dead code
@czyh2022
Copy link
Contributor Author

Got it! I removed dead code and simplified the loop. Although I started playing this game several years ago, I am new here to contributing :)

@yairm210 yairm210 merged commit 87817dd into yairm210:master Dec 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defensive pact involve the 4th nations in the war
4 participants