diff --git a/src/main/java/org/openRealmOfStars/game/GameCommands.java b/src/main/java/org/openRealmOfStars/game/GameCommands.java index 38d3f5881..f63c10075 100644 --- a/src/main/java/org/openRealmOfStars/game/GameCommands.java +++ b/src/main/java/org/openRealmOfStars/game/GameCommands.java @@ -564,6 +564,11 @@ private GameCommands() { */ public static final String COMMAND_DIFFICULT_SETUP = "DifficultSetup"; + /** + * StartingScenario has changed in Galaxy Setup + */ + public static final String COMMAND_SCENARIO_SETUP = "ScenarioSetup"; + /** * Random name button action */ diff --git a/src/main/java/org/openRealmOfStars/game/state/PlayerSetupView.java b/src/main/java/org/openRealmOfStars/game/state/PlayerSetupView.java index 0e5889607..d294ae029 100644 --- a/src/main/java/org/openRealmOfStars/game/state/PlayerSetupView.java +++ b/src/main/java/org/openRealmOfStars/game/state/PlayerSetupView.java @@ -49,6 +49,7 @@ import org.openRealmOfStars.gui.util.GuiStatics; import org.openRealmOfStars.player.AiDifficulty; import org.openRealmOfStars.player.PlayerColor; +import org.openRealmOfStars.player.StartingScenario; import org.openRealmOfStars.player.government.GovernmentType; import org.openRealmOfStars.player.government.GovernmentUtility; import org.openRealmOfStars.player.race.SpaceRace; @@ -106,6 +107,11 @@ public class PlayerSetupView extends BlackPanel { */ private SpaceComboBox[] comboDifficult; + /** + * Combobox for selecting starting scenario for each realm. + */ + private SpaceComboBox[] comboScenario; + /** * Galaxy config */ @@ -163,6 +169,7 @@ public PlayerSetupView(final GalaxyConfig config, raceImgs = new RaceImagePanel[StarMap.MAX_PLAYERS]; playerName = new JTextField[StarMap.MAX_PLAYERS]; comboRealmColor = new SpaceComboBox[StarMap.MAX_PLAYERS]; + comboScenario = new SpaceComboBox[StarMap.MAX_PLAYERS]; SpaceGreyPanel xgrey = new SpaceGreyPanel(); xgrey.setLayout(new GridLayout(4, 4)); @@ -266,6 +273,20 @@ public void handleActions(final ActionEvent arg0) { } } } + if (arg0.getActionCommand().startsWith( + GameCommands.COMMAND_SCENARIO_SETUP)) { + SoundPlayer.playMenuSound(); + for (int i = 0; i < StarMap.MAX_PLAYERS; i++) { + if (comboScenario[i].isEnabled()) { + StartingScenario scenario = (StartingScenario) comboScenario[i] + .getSelectedItem(); + if (scenario != null) { + config.setStartingScenario(i, scenario); + comboScenario[i].setToolTipText(scenario.getDescription()); + } + } + } + } if (arg0.getActionCommand().startsWith( GameCommands.COMMAND_COLOR_SETUP)) { SoundPlayer.playMenuSound(); @@ -440,6 +461,19 @@ private InvisiblePanel createPlayerRaceSelection(final SpaceGreyPanel base, + " statistics."); info.add(comboRealmColor[index]); info.add(Box.createRigidArea(new Dimension(5, 5))); + comboScenario[index] = new SpaceComboBox<>(StartingScenario.values()); + comboScenario[index] + .setBackground(GuiStatics.getDeepSpaceDarkColor()); + comboScenario[index].setForeground(GuiStatics.getCoolSpaceColor()); + comboScenario[index].setBorder(new SimpleBorder()); + comboScenario[index].setFont(GuiFonts.getFontCubellan()); + comboScenario[index].setMaximumSize(new Dimension(Integer.MAX_VALUE, + GuiStatics.TEXT_FIELD_HEIGHT)); + comboScenario[index].setActionCommand( + GameCommands.COMMAND_SCENARIO_SETUP); + comboScenario[index].addActionListener(listener); + info.add(comboScenario[index]); + info.add(Box.createRigidArea(new Dimension(5, 5))); xinvis.add(info); xinvis.add(Box.createRigidArea(new Dimension(25, 25))); return xinvis; diff --git a/src/main/java/org/openRealmOfStars/gui/list/StartingScenarioListRenderer.java b/src/main/java/org/openRealmOfStars/gui/list/StartingScenarioListRenderer.java new file mode 100644 index 000000000..e4fdbd6a7 --- /dev/null +++ b/src/main/java/org/openRealmOfStars/gui/list/StartingScenarioListRenderer.java @@ -0,0 +1,56 @@ +package org.openRealmOfStars.gui.list; +/* + * Open Realm of Stars game project + * Copyright (C) 2024 Tuomo Untinen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/ + */ + +import java.awt.Component; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; + +import org.openRealmOfStars.gui.util.GuiFonts; +import org.openRealmOfStars.player.StartingScenario; + +/** +* +* Starting Scenario list cell renderer +* +*/ +public class StartingScenarioListRenderer + implements ListCellRenderer { + + /** + * Default list cell renderer + */ + private DefaultListCellRenderer defaultRenderer + = new DefaultListCellRenderer(); + + @Override + public Component getListCellRendererComponent( + final JList list, + final StartingScenario value, final int index, final boolean isSelected, + final boolean cellHasFocus) { + JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); + renderer.setFont(GuiFonts.getFontCubellan()); + renderer.setText(value.toString()); + return renderer; + } + +} diff --git a/src/main/java/org/openRealmOfStars/player/PlayerInfo.java b/src/main/java/org/openRealmOfStars/player/PlayerInfo.java index 2f76c99fb..855214a5f 100644 --- a/src/main/java/org/openRealmOfStars/player/PlayerInfo.java +++ b/src/main/java/org/openRealmOfStars/player/PlayerInfo.java @@ -277,6 +277,11 @@ public class PlayerInfo { */ private static final int BOARD_CONTROLLED = 2; + /** + * Realm's staring scenario. + */ + private StartingScenario startingScenario; + /** * Constructor player info. Use this only for JUnits. * @param race Space Race for player @@ -311,6 +316,7 @@ public PlayerInfo(final SpaceRace race, final int maxPlayers, color = PlayerColor.getByIndex(index); aiDifficulty = AiDifficulty.NORMAL; setRandomEventOccured(null); + setStartingScenario(StartingScenario.TEMPERATE_HUMID_SIZE12); setHuman(false); setBoard(false); missions = new MissionList(); @@ -533,6 +539,7 @@ public PlayerInfo(final DataInputStream dis) throws IOException { } artifactLists = new ArtifactLists(dis); color = PlayerColor.getByIndex(dis.read()); + startingScenario = StartingScenario.getByIndex(dis.read()); aiDifficulty = AiDifficulty.getByIndex(dis.read()); government = GovernmentUtility.getGovernmentByIndex(dis.readInt()); warFatigue = dis.readInt(); @@ -657,6 +664,7 @@ public void savePlayerInfo(final DataOutputStream dos) throws IOException { } artifactLists.saveArtifactLists(dos); dos.writeByte(color.getIndex()); + dos.writeByte(startingScenario.getIndex()); dos.writeByte(aiDifficulty.getIndex()); dos.writeInt(government.getIndex()); dos.writeInt(warFatigue); @@ -2294,5 +2302,19 @@ public void appendStory(final String newStory, final int starYear) { Thread.dumpStack(); } } + /** + * Get Starting scenario. + * @return the startingScenario + */ + public StartingScenario getStartingScenario() { + return startingScenario; + } + /** + * Set starting scenario. + * @param startingScenario the startingScenario to set + */ + public void setStartingScenario(final StartingScenario startingScenario) { + this.startingScenario = startingScenario; + } } diff --git a/src/main/java/org/openRealmOfStars/player/PlayerList.java b/src/main/java/org/openRealmOfStars/player/PlayerList.java index 2e55c195a..cd9070b01 100644 --- a/src/main/java/org/openRealmOfStars/player/PlayerList.java +++ b/src/main/java/org/openRealmOfStars/player/PlayerList.java @@ -109,6 +109,11 @@ public static PlayerList createPlayerList(final GalaxyConfig galaxyConfig) { info.setElderRealm(galaxyConfig.getPlayerElderRealm(i)); info.setAiDifficulty(galaxyConfig.getDifficulty(i)); info.setColor(galaxyConfig.getPlayerColor(i)); + StartingScenario scenario = galaxyConfig.getStartingScenario(i); + if (scenario == StartingScenario.RANDOM) { + scenario = StartingScenario.pickRandom(); + } + info.setStartingScenario(scenario); randomListOfColors.remove(galaxyConfig.getPlayerColor(i)); if (i == 0 && !galaxyConfig.isAiOnly()) { info.setHuman(true); diff --git a/src/main/java/org/openRealmOfStars/player/StartingScenario.java b/src/main/java/org/openRealmOfStars/player/StartingScenario.java new file mode 100644 index 000000000..4fa6ab8ac --- /dev/null +++ b/src/main/java/org/openRealmOfStars/player/StartingScenario.java @@ -0,0 +1,108 @@ +package org.openRealmOfStars.player; + +import java.util.ArrayList; + +import org.openRealmOfStars.utilities.DiceGenerator; + +/* + * Open Realm of Stars game project + * Copyright (C) 2023-2024 Tuomo Untinen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/ + */ + +/** + * Starting Scenarion enumeration for Open Realm of Stars + */ +public enum StartingScenario { + + /** + * Random starting scenario. + */ + RANDOM, + /** + * So called standard starting scenario. + * Temperate humind planet with size 12. + */ + TEMPERATE_HUMID_SIZE12, + /** + * Starting system is sol. + */ + EARTH; + + /** + * Get starting scenarion as an integer value. + * @return int + */ + public int getIndex() { + switch (this) { + case RANDOM: return 0; + case TEMPERATE_HUMID_SIZE12: return 1; + case EARTH: return 2; + default: throw new IllegalArgumentException("Unknown starting scenario."); + } + } + + /** + * Get starting scenario based on index. + * @param index Index + * @return StartingScenario + */ + public static StartingScenario getByIndex(final int index) { + switch (index) { + case 0: return RANDOM; + case 1: return TEMPERATE_HUMID_SIZE12; + case 2: return EARTH; + default: throw new IllegalArgumentException("Unknown starting scenario."); + } + } + + @Override + public String toString() { + switch (this) { + default: + case RANDOM: return "Random starting scenario"; + case TEMPERATE_HUMID_SIZE12: return "Temperate and humid planet"; + case EARTH: return "Start from Earth"; + } + } + + /** + * Get Starting Scenario description. + * @return Description as string. + */ + public String getDescription() { + switch (this) { + default: + case RANDOM: return "Random starting scenario."; + case TEMPERATE_HUMID_SIZE12: return "Temperate and humid planet with" + + " ground size 12. World type is either Swamp or water planet."; + case EARTH: return "Realm starts at Earth and solar system is Sol."; + } + } + + /** + * Pick Random starting scenario. + * @return Statring Scenario + */ + public static StartingScenario pickRandom() { + ArrayList list = new ArrayList<>(); + for (StartingScenario scenario : StartingScenario.values()) { + if (scenario != RANDOM) { + list.add(scenario); + } + } + return DiceGenerator.pickRandom(list); + } +} diff --git a/src/main/java/org/openRealmOfStars/starMap/GalaxyConfig.java b/src/main/java/org/openRealmOfStars/starMap/GalaxyConfig.java index bed9594b8..a89134e87 100644 --- a/src/main/java/org/openRealmOfStars/starMap/GalaxyConfig.java +++ b/src/main/java/org/openRealmOfStars/starMap/GalaxyConfig.java @@ -19,6 +19,7 @@ import org.openRealmOfStars.player.AiDifficulty; import org.openRealmOfStars.player.PlayerColor; +import org.openRealmOfStars.player.StartingScenario; import org.openRealmOfStars.player.government.GovernmentType; import org.openRealmOfStars.player.government.GovernmentUtility; import org.openRealmOfStars.player.race.SpaceRace; @@ -135,6 +136,8 @@ public class GalaxyConfig { */ private boolean[] playerElderRealm; + /** Player Starting scenario */ + private StartingScenario[] startingScenario; /** * Chance for planetary event */ @@ -278,12 +281,14 @@ public GalaxyConfig() { playerElderRealm = new boolean[StarMap.MAX_PLAYERS]; playerDifficult = new AiDifficulty[StarMap.MAX_PLAYERS]; playerColors = new PlayerColor[StarMap.MAX_PLAYERS]; + startingScenario = new StartingScenario[StarMap.MAX_PLAYERS]; setEnableTutorial(true); setAiOnly(false); setAllNews(false); for (int i = 0; i < StarMap.MAX_PLAYERS; i++) { setRace(i, SpaceRaceUtility.getRandomRace()); setPlayerColor(i, DiceGenerator.pickRandom(PlayerColor.values())); + setStartingScenario(i, StartingScenario.RANDOM); while (true) { GovernmentType gov = GovernmentUtility.getRandomGovernment(); setPlayerGovernment(i, gov); @@ -405,6 +410,29 @@ public PlayerColor getPlayerColor(final int index) { return null; } + /** + * Set player starting scenario. + * @param index PlayerIndex + * @param scenario Starting Scenario + */ + public void setStartingScenario(final int index, + final StartingScenario scenario) { + if (index >= 0 && index < StarMap.MAX_PLAYERS) { + startingScenario[index] = scenario; + } + } + + /** + * Get starting scenario for player index. + * @param index PlayerIndex + * @return StartingScenario or null if out of bounds. + */ + public StartingScenario getStartingScenario(final int index) { + if (index >= 0 && index < StarMap.MAX_PLAYERS) { + return startingScenario[index]; + } + return null; + } /** * Get Player difficulty. * @param index Player Index diff --git a/src/main/java/org/openRealmOfStars/starMap/StarMapGenerator.java b/src/main/java/org/openRealmOfStars/starMap/StarMapGenerator.java index 97cb9e6fd..52b727ed5 100644 --- a/src/main/java/org/openRealmOfStars/starMap/StarMapGenerator.java +++ b/src/main/java/org/openRealmOfStars/starMap/StarMapGenerator.java @@ -29,6 +29,7 @@ import org.openRealmOfStars.mapTiles.Tiles; import org.openRealmOfStars.player.PlayerInfo; import org.openRealmOfStars.player.PlayerList; +import org.openRealmOfStars.player.StartingScenario; import org.openRealmOfStars.player.fleet.Fleet; import org.openRealmOfStars.player.leader.Job; import org.openRealmOfStars.player.leader.Leader; @@ -36,7 +37,6 @@ import org.openRealmOfStars.player.message.Message; import org.openRealmOfStars.player.message.MessageType; import org.openRealmOfStars.player.race.BackgroundStoryGenerator; -import org.openRealmOfStars.player.race.SpaceRace; import org.openRealmOfStars.player.race.trait.TraitIds; import org.openRealmOfStars.player.ship.Ship; import org.openRealmOfStars.player.ship.ShipHullType; @@ -750,10 +750,13 @@ private void createSolarSystem(final int sunx, final int suny, if (playerIndex != -1) { PlayerInfo playerInfo = starMap.getPlayerList().getPlayerInfoByIndex( playerIndex); - if (playerInfo.getRace() == SpaceRace.HUMAN && !solHasAdded) { - solHasAdded = true; - createSolSystem(sunx, suny, playerIndex, config); - return; + if (playerInfo.getStartingScenario() == StartingScenario.EARTH) { + if (!solHasAdded) { + solHasAdded = true; + createSolSystem(sunx, suny, playerIndex, config); + return; + } + playerInfo.setStartingScenario(StartingScenario.TEMPERATE_HUMID_SIZE12); } } if (playerIndex == -1 && !solHasAdded diff --git a/src/test/java/org/openRealmOfStars/ai/planet/PlanetHandlingTest.java b/src/test/java/org/openRealmOfStars/ai/planet/PlanetHandlingTest.java index 0625e4b35..26e189795 100644 --- a/src/test/java/org/openRealmOfStars/ai/planet/PlanetHandlingTest.java +++ b/src/test/java/org/openRealmOfStars/ai/planet/PlanetHandlingTest.java @@ -29,6 +29,7 @@ import org.openRealmOfStars.player.AiDifficulty; import org.openRealmOfStars.player.PlayerInfo; import org.openRealmOfStars.player.PlayerList; +import org.openRealmOfStars.player.StartingScenario; import org.openRealmOfStars.player.diplomacy.Attitude; import org.openRealmOfStars.player.diplomacy.Diplomacy; import org.openRealmOfStars.player.diplomacy.DiplomacyBonusList; @@ -461,6 +462,7 @@ public void testBasicHighScoring() { PlayerInfo info = new PlayerInfo(SpaceRace.HUMAN, 2, 0); info.setEmpireName("Human Kingdom"); info.setGovernment(GovernmentType.KINGDOM); + info.setStartingScenario(StartingScenario.EARTH); PlayerInfo info2 = new PlayerInfo(SpaceRace.HUMAN, 2, 1); info2.setEmpireName("Terran Federation"); info2.setGovernment(GovernmentType.FEDERATION); @@ -468,6 +470,8 @@ public void testBasicHighScoring() { GalaxyConfig config = new GalaxyConfig(); config.setPlayerName(0, info.getEmpireName()); config.setPlayerName(1, info2.getEmpireName()); + config.setStartingScenario(0, StartingScenario.EARTH); + config.setStartingScenario(1, StartingScenario.TEMPERATE_HUMID_SIZE12); config.setMaxPlayers(2); PlayerList playerList = new PlayerList(); playerList.addPlayer(info);