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

isAI to check AI controlled players. #11979

Merged
merged 7 commits into from
Sep 29, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class RulesAttachment extends AbstractPlayerRulesAttachment {
private int techCount = -1;
// condition for having specific relationships
private @Nullable List<String> relationship = null;
// condition for checking ai player
private boolean checkAIPlayers = false;
WCSumpton marked this conversation as resolved.
Show resolved Hide resolved
// condition for being at war
private @Nullable Set<GamePlayer> atWarPlayers = null;
private int atWarCount = -1;
Expand Down Expand Up @@ -489,6 +491,22 @@ private void resetUnitPresence() {
unitPresence = null;
}

private void setCheckAIPlayers(final String s) {
checkAIPlayers = getBool(s);
}

private void setCheckAIPlayers(final Boolean s) {
checkAIPlayers = s;
}

public boolean getCheckAIPlayers() {
return checkAIPlayers;
}

private void resetCheckAIPlayers() {
checkAIPlayers = false;
}

private int getAtWarCount() {
return atWarCount;
}
Expand Down Expand Up @@ -735,11 +753,17 @@ public boolean isSatisfied(
}
objectiveMet = checkDirectOwnership(listedTerritories, players);
}
// check for ai controlled player
if (objectiveMet && getCheckAIPlayers()) {
objectiveMet = checkCheckAIPlayers(players);
}
// get attached to player
final GamePlayer playerAttachedTo = (GamePlayer) getAttachedTo();
// check for players at war
if (objectiveMet && !getAtWarPlayers().isEmpty()) {
objectiveMet = checkAtWar(playerAttachedTo, getAtWarPlayers(), getAtWarCount());
}
// check for techs
if (objectiveMet && !getTechs().isEmpty()) {
objectiveMet = checkTechs(playerAttachedTo, data.getTechnologyFrontier());
}
Expand Down Expand Up @@ -1001,6 +1025,14 @@ private boolean matchTerritories(
return numberMet >= getTerritoryCount();
}

private boolean checkCheckAIPlayers(final List<GamePlayer> players) {
boolean bcheck = true;
for (GamePlayer player : players) {
bcheck = (bcheck && player.isAi());
}
return bcheck;
}

private boolean checkAtWar(
final GamePlayer player, final Set<GamePlayer> enemies, final int count) {
int found = CollectionUtils.countMatches(enemies, player::isAtWar);
Expand Down Expand Up @@ -1057,6 +1089,12 @@ public MutableProperty<?> getPropertyOrNull(String propertyName) {
this::setRelationship,
this::getRelationship,
this::resetRelationship);
case "checkAIPlayer":
return MutableProperty.of(
this::setCheckAIPlayers,
this::setCheckAIPlayers,
this::getCheckAIPlayers,
this::resetCheckAIPlayers);
case "atWarPlayers":
return MutableProperty.of(
this::setAtWarPlayers,
Expand Down