Skip to content

Commit

Permalink
#700 Adds starting scenario system.
Browse files Browse the repository at this point in the history
There are now three different scenarios:
Random, Temperate, humid planet size 12 and Earth.
  • Loading branch information
tuomount committed Feb 1, 2024
1 parent ed6cf92 commit 162f8b9
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/openRealmOfStars/game/GameCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/openRealmOfStars/game/state/PlayerSetupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,11 @@ public class PlayerSetupView extends BlackPanel {
*/
private SpaceComboBox<AiDifficulty>[] comboDifficult;

/**
* Combobox for selecting starting scenario for each realm.
*/
private SpaceComboBox<StartingScenario>[] comboScenario;

/**
* Galaxy config
*/
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -440,6 +461,19 @@ private InvisiblePanel createPlayerRaceSelection(final SpaceGreyPanel base,
+ " statistics.</html>");
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StartingScenario> {

/**
* Default list cell renderer
*/
private DefaultListCellRenderer defaultRenderer
= new DefaultListCellRenderer();

@Override
public Component getListCellRendererComponent(
final JList<? extends StartingScenario> 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;
}

}
22 changes: 22 additions & 0 deletions src/main/java/org/openRealmOfStars/player/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
5 changes: 5 additions & 0 deletions src/main/java/org/openRealmOfStars/player/PlayerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/org/openRealmOfStars/player/StartingScenario.java
Original file line number Diff line number Diff line change
@@ -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<StartingScenario> list = new ArrayList<>();
for (StartingScenario scenario : StartingScenario.values()) {
if (scenario != RANDOM) {
list.add(scenario);
}
}
return DiceGenerator.pickRandom(list);
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/openRealmOfStars/starMap/GalaxyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +136,8 @@ public class GalaxyConfig {
*/
private boolean[] playerElderRealm;

/** Player Starting scenario */
private StartingScenario[] startingScenario;
/**
* Chance for planetary event
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 162f8b9

Please sign in to comment.