Skip to content

Commit

Permalink
add option to make the AI build more towers
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwedeck committed Jan 23, 2023
1 parent 67817ba commit ee3d6c5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ public abstract class CommonConstants {
public static Supplier<Boolean> PLAYALL_MUSIC = () -> false;

public static Supplier<Float> MUSIC_VOLUME = () -> 1f;

public static Supplier<Boolean> AI_MORE_TOWERS = () -> false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import jsettlers.ai.highlevel.pioneers.PioneerGroup;
import jsettlers.ai.highlevel.pioneers.target.SameBlockedPartitionLikePlayerFilter;
import jsettlers.ai.highlevel.pioneers.target.SurroundedByResourcesFilter;
import jsettlers.common.CommonConstants;
import jsettlers.common.buildings.EBuildingType;
import jsettlers.common.landscape.EResourceType;
import jsettlers.common.material.EMaterialType;
import jsettlers.common.movable.EMovableType;
import jsettlers.common.player.ECivilisation;
import jsettlers.common.player.IInGamePlayer;
import jsettlers.common.player.IPlayer;
import jsettlers.common.position.ShortPoint2D;
import jsettlers.input.tasks.ConstructBuildingTask;
import jsettlers.input.tasks.ConvertGuiTask;
Expand All @@ -46,6 +48,7 @@
import jsettlers.input.tasks.MoveToGuiTask;
import jsettlers.input.tasks.WorkAreaGuiTask;
import jsettlers.logic.buildings.Building;
import jsettlers.logic.constants.MatchConstants;
import jsettlers.logic.map.grid.MainGrid;
import jsettlers.logic.map.grid.movable.MovableGrid;
import jsettlers.logic.movable.interfaces.ILogicMovable;
Expand All @@ -55,7 +58,7 @@
import static jsettlers.common.buildings.EBuildingType.*;
import static jsettlers.common.material.EMaterialType.GEMS;
import static jsettlers.common.material.EMaterialType.GOLD;
import static jsettlers.common.material.EMaterialType.MEAD;

import jsettlers.common.action.EMoveToType;

/**
Expand Down Expand Up @@ -313,7 +316,26 @@ private boolean buildTower() {
}
}

List<ShortPoint2D> threatenedBorder = aiStatistics.threatenedBorderOf(playerId);
List<ShortPoint2D> threatenedBorder = new ArrayList<>();
if(CommonConstants.AI_MORE_TOWERS.get()) {
int width = mainGrid.getWidth();
int height = mainGrid.getHeight();

// just guess some tower positions
for(int i = 0; i < 1000; i++) {
int x = MatchConstants.aiRandom().nextInt(0, width);
int y = MatchConstants.aiRandom().nextInt(0, height);

IPlayer player = mainGrid.getPartitionsGrid().getPlayerAt(x, y);
if (player == null || player.getPlayerId() != playerId) continue;

if (!mainGrid.getPartitionsGrid().isEnforcedByTower(x, y)) {
threatenedBorder.add(new ShortPoint2D(x, y));
}
}
}

threatenedBorder.addAll(aiStatistics.threatenedBorderOf(playerId));
if (threatenedBorder.size() == 0) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class SettingsMenuPanel extends JPanel {
private final JCheckBox playAllMusicCheckBox = new JCheckBox();
private final SettingsSlider fpsLimitSlider = new SettingsSlider("fps", 0,240, "timerless redraw");
private final SettingsSlider guiScaleSlider = new SettingsSlider("%", 50,400, "system default");
private final JCheckBox aiTowerFocusCheckBox = new JCheckBox();
private final BackendSelector backendSelector = new BackendSelector();

/**
Expand Down Expand Up @@ -87,6 +88,7 @@ public SettingsMenuPanel(MainMenuPanel mainMenuPanel) {
addSetting("settings-backend", backendSelector);

addSetting("settings-gui-scale", guiScaleSlider);
addSetting("settings-ai-tower-focus", aiTowerFocusCheckBox);

initButton();
}
Expand Down Expand Up @@ -125,6 +127,7 @@ private void initButton() {
settingsManager.setFpsLimit(fpsLimitSlider.getValue());
settingsManager.setBackend(backendSelector.getSelectedItem()+"");
settingsManager.setGuiScale(guiScaleSlider.getValue()/100f);
settingsManager.setAiNoPioneers(aiTowerFocusCheckBox.isSelected());
mainMenuPanel.reset();
});

Expand All @@ -144,5 +147,6 @@ public void initializeValues() {
fpsLimitSlider.setValue(settingsManager.getFpsLimit());
backendSelector.setSelectedItem(settingsManager.getBackend());
guiScaleSlider.setValue(Math.round(settingsManager.getGuiScale()*100));
aiTowerFocusCheckBox.setSelected(settingsManager.getAiTowerFocus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class SettingsManager implements ISoundSettingsProvider {
private static final String SETTING_BUILDING = "building";
private static final String SETTING_CIVILISATION = "civ";

private static final String SETTING_AI_TOWER_FOCUS = "ai-tower-focus";

private static SettingsManager manager;

private final Properties storedSettings = new Properties();
Expand All @@ -82,6 +84,7 @@ public static void setup(String... args) throws IOException {

CommonConstants.PLAYALL_MUSIC = manager::isMusicPlayAll;
CommonConstants.MUSIC_VOLUME = manager::getMusicVolume;
CommonConstants.AI_MORE_TOWERS = manager::getAiTowerFocus;
}

public static SettingsManager getInstance() {
Expand Down Expand Up @@ -224,9 +227,19 @@ public Optional<ECivilisation> getCivilisation() {
.map(s -> ECivilisation.valueOf(s.toUpperCase()));
}

public boolean getAiTowerFocus() {
return Optional.ofNullable(get(SETTING_AI_TOWER_FOCUS))
.map(Boolean::parseBoolean)
.orElse(false);
}

public EBackendType getBackend() {
return BackendSelector.getBackendByName(getOrDefault(SETTING_BACKEND, () -> EBackendType.DEFAULT.cc_name));
}

public void setAiNoPioneers(boolean aiNoPioneers) {
set(SETTING_AI_TOWER_FOCUS, Boolean.toString(aiNoPioneers));
}
public void setVolume(float volume) {
set(SETTING_VOLUME, Float.toString(volume));
}
Expand Down

0 comments on commit ee3d6c5

Please sign in to comment.