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 4 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
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 isAI = null;
asvitkine 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 setIsAI(final String s) {
isAI = (s == null) ? null : getBool(s);
}

private void setIsAI(final Boolean s) {
isAI = s;
}

public Boolean getIsAI() {
return isAI;
}

private void resetIsAI() {
isAI = null;
}

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 && getIsAI() != null) {
objectiveMet = checkIsAI(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 checkIsAI(final List<GamePlayer> players) {
boolean bcheck = true;
for (GamePlayer player : players) {
bcheck = (bcheck && (getIsAI() == 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,8 @@ public MutableProperty<?> getPropertyOrNull(String propertyName) {
this::setRelationship,
this::getRelationship,
this::resetRelationship);
case "isAI":
return MutableProperty.of(this::setIsAI, this::setIsAI, this::getIsAI, this::resetIsAI);
case "atWarPlayers":
return MutableProperty.of(
this::setAtWarPlayers,
Expand Down