Skip to content

Commit

Permalink
#737 Fixes issues when randomizing AI realms.
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomount committed Mar 27, 2024
1 parent 9596f52 commit f2e10d3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/openRealmOfStars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ private void actionPerformedMenus(final ActionEvent arg0) {
changeGameState(GameState.SAVE_GAME_NAME_VIEW);
return;
}
//TODO: Handle actions
aiRealmSetupView.handleActions(arg0);
}
if (gameState == GameState.REALM_SETUP_VIEW && realmSetupView != null) {
if (arg0.getActionCommand()
Expand Down Expand Up @@ -3019,7 +3019,7 @@ private void actionPerformedMenus(final ActionEvent arg0) {
.equalsIgnoreCase(GameCommands.COMMAND_NEXT)) {
SoundPlayer.playMenuSound();
if (!saveGameView.isContinueGame()) {
playerSetupView.getNamesToConfig();
//playerSetupView.getNamesToConfig();
saveFilename = saveGameView.getFilename();
changeGameState(GameState.NEW_GAME);
} else {
Expand Down Expand Up @@ -3964,6 +3964,7 @@ public void actionPerformed(final ActionEvent arg0) {
|| gameState == GameState.GAME_END_VIEW
|| gameState == GameState.STORY_VIEW
|| gameState == GameState.REALM_SETUP_VIEW
|| gameState == GameState.AI_REALM_SETUP_VIEW
|| gameState == GameState.END_STORY_VIEW) {
actionPerformedMenus(arg0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import org.openRealmOfStars.player.government.GovernmentType;
import org.openRealmOfStars.player.race.SpaceRace;
import org.openRealmOfStars.player.race.SpaceRaceFactory;
import org.openRealmOfStars.player.scenario.StartingScenario;
import org.openRealmOfStars.player.scenario.StartingScenarioFactory;
import org.openRealmOfStars.player.scenario.StartingScenarioType;
import org.openRealmOfStars.player.ship.generator.ShipGenerator;
import org.openRealmOfStars.starMap.Coordinate;
import org.openRealmOfStars.starMap.GalaxyConfig;
Expand Down Expand Up @@ -97,6 +100,10 @@ public class AiRealmSetupView extends BlackPanel {
*/
private SpaceComboBox<String> comboMaximumElderRace;

/**
* Generated realms based on settings.
*/
private boolean generated;
/**
* Constructor for AI Realm setup View
* @param config Galaxy Configuration
Expand All @@ -109,6 +116,7 @@ public AiRealmSetupView(final GalaxyConfig config,
} else {
this.config = config;
}
generated = false;
Planet planet = new Planet(new Coordinate(1, 1), "AI Realm Setup Planet",
1, false);
planet.setPlanetType(PlanetTypes.getRandomPlanetType(true, true, true));
Expand Down Expand Up @@ -287,11 +295,13 @@ private InfoPanel createRealmSetupPanel(final ActionListener listener) {
utopiaStart.setSelected(true);
info.add(utopiaStart);
info.add(Box.createRigidArea(new Dimension(5, 5)));
SpaceButton btn = new SpaceButton("Edit details",
// TODO: Add this when GalaxyConfig allows adding random spacerace,
// governments and so on.
/*SpaceButton btn = new SpaceButton("Edit details",
GameCommands.COMMAND_REALM_DETAILS);
btn.setAlignmentX(CENTER_ALIGNMENT);
btn.addActionListener(listener);
info.add(btn);
info.add(btn);*/
info.add(Box.createRigidArea(new Dimension(5, 5)));
return info;
}
Expand All @@ -312,20 +322,44 @@ public void generateRealms() {
}
int countElder = 0;
ArrayList<SpaceRace> availableRaces = new ArrayList<>();
for (String name : SpaceRaceFactory.getNames()) {
for (String name : SpaceRaceFactory.getIds()) {
availableRaces.add(SpaceRaceFactory.createOne(name));
}
availableRaces.remove(config.getRace(0));
ArrayList<GovernmentType> availableGovs = new ArrayList<>();
for (GovernmentType government : GovernmentType.values()) {
availableGovs.add(government);
}
availableGovs.remove(config.getPlayerGovernment(0));
if (uniqueGovernment.isSelected()) {
availableGovs.remove(config.getPlayerGovernment(0));
}
ArrayList<PlayerColor> availableColors = new ArrayList<>();
for (PlayerColor color : PlayerColor.values()) {
availableColors.add(color);
}
availableColors.remove(config.getPlayerColor(0));
ArrayList<StartingScenario> availableScenario = new ArrayList<>();
for (StartingScenario scenario : StartingScenarioFactory.getValues()) {
if (scenario.getType() == StartingScenarioType.REGULAR) {
if (scenario.getId().equals("EARTH") && startEarth.isSelected()) {
availableScenario.add(scenario);
continue;
}
if (!scenario.getId().equals("EARTH")) {
availableScenario.add(scenario);
continue;
}
}
if (scenario.getType() == StartingScenarioType.NO_HOME
&& noHomeStart.isSelected()) {
availableScenario.add(scenario);
}
if (scenario.getType() == StartingScenarioType.UTOPIA_WORLD
&& utopiaStart.isSelected()) {
availableScenario.add(scenario);
}
}

for (int i = 1; i < config.getMaxPlayers(); i++) {
if (countElder < elders) {
countElder++;
Expand Down Expand Up @@ -360,8 +394,14 @@ public void generateRealms() {
* @param arg0 The event
*/
public void handleActions(final ActionEvent arg0) {
if (arg0.getActionCommand().equals(GameCommands.COMMAND_ANIMATION_TIMER)
&& !generated) {
generateRealms();
generated = true;
}
if (arg0.getActionCommand().equals(GameCommands.COMMAND_GALAXY_SETUP)) {
SoundPlayer.playMenuSound();
generateRealms();
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/openRealmOfStars/player/race/SpaceRace.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,9 @@ public boolean isMonster() {
public boolean isPirate() {
return this.spaceRaceType == SpaceRaceType.SPACE_PIRATE;
}

@Override
public String toString() {
return getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ public static String[] getNames() {
return names.toArray(new String[names.size()]);
}

/**
* Get All Space race ids in array. This will filter out pseudo races.
* @return Space race ids array
*/
public static String[] getIds() {
SpaceRace[] races = SINGLETON.getAll();
ArrayList<String> names = new ArrayList<>();
for (SpaceRace race : races) {
if (race.getSpaceRaceType() == SpaceRaceType.REGULAR) {
names.add(race.getId());
}
}
return names.toArray(new String[names.size()]);
}

/**
* Get random living race.
* @return Living SpaceRace
Expand Down

0 comments on commit f2e10d3

Please sign in to comment.