Skip to content

Commit

Permalink
#700 Adds new starting scenarios.
Browse files Browse the repository at this point in the history
Fixes few JUnits.
Fixes one missing temperature from toString().
Adds maximum population amount in planet view.
  • Loading branch information
tuomount committed Feb 2, 2024
1 parent 0747352 commit 0533937
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 26 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/openRealmOfStars/game/state/PlanetView.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,15 @@ public PlanetView(final Planet planet, final boolean interactive,
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
totalPeople = new IconLabel(null,
Icons.getIconByName(Icons.ICON_PEOPLE), ": 00");
totalPeople.setToolTipText("Total number of people on planet.");
String maxPop = "";
if (planet.getPlanetPlayerInfo() != null) {
maxPop = "Maximum population is "
+ String.valueOf(planet.getPopulationLimit());
} else {
maxPop = "Maximum population if colonized is "
+ String.valueOf(planet.getPopulationLimit(player));
}
totalPeople.setToolTipText("Total number of people on planet. " + maxPop);
totalPeople.setAlignmentX(Component.LEFT_ALIGNMENT);
panel.add(totalPeople);
farmPanel = new WorkerProductionPanel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private InvisiblePanel createPlayerRaceSelection(final SpaceGreyPanel base,
final int index, final ActionListener listener) {
InvisiblePanel xinvis = new InvisiblePanel(base);
xinvis.setLayout(new BoxLayout(xinvis, BoxLayout.X_AXIS));
xinvis.add(Box.createRigidArea(new Dimension(25, 25)));
xinvis.add(Box.createRigidArea(new Dimension(10, 10)));

InfoPanel info = new InfoPanel();
info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
Expand Down Expand Up @@ -475,7 +475,7 @@ private InvisiblePanel createPlayerRaceSelection(final SpaceGreyPanel base,
info.add(comboScenario[index]);
info.add(Box.createRigidArea(new Dimension(5, 5)));
xinvis.add(info);
xinvis.add(Box.createRigidArea(new Dimension(25, 25)));
xinvis.add(Box.createRigidArea(new Dimension(10, 10)));
return xinvis;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/openRealmOfStars/player/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ public PlayerInfo(final SpaceRace race, final int maxPlayers,
extraTech[0] = "randomElectronics";
extraTech[1] = "randomPropulsion";
}
if (getStartingScenario() == StartingScenario.COLD_HUMID_SIZE12) {
extraTech = new String[1];
extraTech[0] = "randomImprovement";
}
if (getStartingScenario() == StartingScenario.HOT_ARID_SIZE12) {
extraTech = new String[2];
extraTech[0] = "randomElectronics";
extraTech[1] = "randomCombat";
}
setFakeMilitarySize(100);
// This is the old way of government
setGovernment(GovernmentType.AI);
Expand Down
61 changes: 56 additions & 5 deletions src/main/java/org/openRealmOfStars/player/StartingScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,38 @@ public enum StartingScenario {
RANDOM,
/**
* So called standard starting scenario.
* Temperate humind planet with size 12.
* Temperate humid planet with size 12.
*/
TEMPERATE_HUMID_SIZE12,
/**
* Starting system is sol.
*/
EARTH,
/**
* Arid planet size 12, single extra technology for starters.
* Arid planet size 12, two extra technology for starters.
*/
TEMPERATE_ARID_SIZE12;
TEMPERATE_ARID_SIZE12,
/**
* Marine planet size 9.
*/
TEMPERATE_MARINE_SIZE9,
/**
* Marine planet size 14.
*/
TEMPERATE_MARINE_SIZE14,
/**
* Cold humid planet size 12, extra technology for starters.
*/
COLD_HUMID_SIZE12,
/**
* Tropical humid planet size 12
*/
TROPICAL_HUMID_SIZE12,
/**
* Hot arid planet size 12, extra technology for starters.
*/
HOT_ARID_SIZE12;


/**
* Get starting scenarion as an integer value.
Expand All @@ -55,6 +76,11 @@ public int getIndex() {
case TEMPERATE_HUMID_SIZE12: return 1;
case EARTH: return 2;
case TEMPERATE_ARID_SIZE12: return 3;
case TEMPERATE_MARINE_SIZE9: return 4;
case TEMPERATE_MARINE_SIZE14: return 5;
case COLD_HUMID_SIZE12: return 6;
case TROPICAL_HUMID_SIZE12: return 7;
case HOT_ARID_SIZE12: return 8;
default: throw new IllegalArgumentException("Unknown starting scenario.");
}
}
Expand All @@ -70,6 +96,11 @@ public static StartingScenario getByIndex(final int index) {
case 1: return TEMPERATE_HUMID_SIZE12;
case 2: return EARTH;
case 3: return TEMPERATE_ARID_SIZE12;
case 4: return TEMPERATE_MARINE_SIZE9;
case 5: return TEMPERATE_MARINE_SIZE14;
case 6: return COLD_HUMID_SIZE12;
case 7: return TROPICAL_HUMID_SIZE12;
case 8: return HOT_ARID_SIZE12;
default: throw new IllegalArgumentException("Unknown starting scenario.");
}
}
Expand All @@ -81,7 +112,15 @@ public String toString() {
case RANDOM: return "Random starting scenario";
case TEMPERATE_HUMID_SIZE12: return "Temperate and humid planet";
case EARTH: return "Start from Earth";
case TEMPERATE_ARID_SIZE12: return "Temperate and arid, with extra tech";
case TEMPERATE_ARID_SIZE12: return "Temperate and arid planet,"
+ " with extra tech";
case TEMPERATE_MARINE_SIZE9: return "Temperate, marine and low gravity"
+ " planet";
case TEMPERATE_MARINE_SIZE14: return "Temperate, marine and high gravity"
+ " planet";
case COLD_HUMID_SIZE12: return "Cold, humid planet with extra tech";
case TROPICAL_HUMID_SIZE12: return "Tropical, humid planet";
case HOT_ARID_SIZE12: return "Hot, arid planet with extra tech";
}
}

Expand All @@ -97,7 +136,19 @@ public String getDescription() {
+ " ground size 12. World type is either Swamp or water planet.";
case EARTH: return "Realm starts at Earth and solar system is Sol.";
case TEMPERATE_ARID_SIZE12: return "Temperate and arid planet with"
+ " ground size 12. World type is desert. Start extra technology.";
+ " ground size 12. World type is desert. Start with extra 2"
+ " technology.";
case TEMPERATE_MARINE_SIZE9: return "Temperate, marine and low gravity"
+ " planet with ground size 9. World type is water world.";
case TEMPERATE_MARINE_SIZE14: return "Temperate, marine and high gravity"
+ " planet with ground size 14. World type is water world.";
case COLD_HUMID_SIZE12: return "Cold and humid planet with"
+ " ground size 12. World type is ice world. Start with extra technology.";
case TROPICAL_HUMID_SIZE12: return "Tropical and humid planet with"
+ " ground size 12. World type is either Swamp or water planet.";
case HOT_ARID_SIZE12: return "Hot and arid planet with"
+ " ground size 12. World type is desert world. Start with extra"
+ " 2 technology.";
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/openRealmOfStars/starMap/StarMapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,31 @@ private void createSolarSystem(final int sunx, final int suny,
planet.setTemperatureType(TemperatureType.TEMPERATE);
planet.setWaterLevel(WaterLevelType.ARID);
planet.setGroundSize(12);
} else if (playerInfo.getStartingScenario()
== StartingScenario.TEMPERATE_MARINE_SIZE9) {
planet.setTemperatureType(TemperatureType.TEMPERATE);
planet.setWaterLevel(WaterLevelType.MARINE);
planet.setGroundSize(9);
} else if (playerInfo.getStartingScenario()
== StartingScenario.TEMPERATE_MARINE_SIZE14) {
planet.setTemperatureType(TemperatureType.TEMPERATE);
planet.setWaterLevel(WaterLevelType.MARINE);
planet.setGroundSize(14);
} else if (playerInfo.getStartingScenario()
== StartingScenario.COLD_HUMID_SIZE12) {
planet.setTemperatureType(TemperatureType.COLD);
planet.setWaterLevel(WaterLevelType.HUMID);
planet.setGroundSize(12);
} else if (playerInfo.getStartingScenario()
== StartingScenario.HOT_ARID_SIZE12) {
planet.setTemperatureType(TemperatureType.HOT);
planet.setWaterLevel(WaterLevelType.ARID);
planet.setGroundSize(12);
} else if (playerInfo.getStartingScenario()
== StartingScenario.TROPICAL_HUMID_SIZE12) {
planet.setTemperatureType(TemperatureType.TROPICAL);
planet.setWaterLevel(WaterLevelType.HUMID);
planet.setGroundSize(12);
} else {
planet.setTemperatureType(TemperatureType.TEMPERATE);
planet.setWaterLevel(WaterLevelType.HUMID);
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/org/openRealmOfStars/starMap/planet/Planet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3063,20 +3063,29 @@ public int getTax() {
* @return Planet's population limit
*/
public int getPopulationLimit() {
return getPopulationLimit(getPlanetPlayerInfo());
}

/**
* Get Planet's population limit based on certain realm.
* @param info PlayerInfo
* @return Planet's population limit
*/
public int getPopulationLimit(final PlayerInfo info) {
int result = 0;
if (planetOwnerInfo != null) {
result = planetOwnerInfo.getRace().getExtraPopulation();
if (info != null) {
result = info.getRace().getExtraPopulation();
}
result = result + getGroundSize();
if (planetOwnerInfo != null) {
int percent = planetOwnerInfo.getPlanetSuitabilityValue(this);
if (info != null) {
int percent = info.getPlanetSuitabilityValue(this);
result = result * percent / 100;
if (result < 2 && percent > 0) {
result = 2;
}
}
if (planetOwnerInfo != null
&& planetOwnerInfo.getRace().hasTrait(TraitIds.ZERO_GRAVITY_BEING)) {
if (info != null
&& info.getRace().hasTrait(TraitIds.ZERO_GRAVITY_BEING)) {
result = 0;
if (getPlanetType() == PlanetTypes.ARTIFICIALWORLD1) {
result = getGroundSize();
Expand All @@ -3103,7 +3112,6 @@ public int getPopulationLimit() {
}
return result;
}

/**
* Is planet full of population or not
* @return True if planet is full of population
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public String toString() {
case ARCTIC: return "arctic";
case COLD: return "cold";
case TEMPERATE: return "temperate";
case TROPICAL: return "tropical";
case HOT: return "hot";
case VOLCANIC: return "volcanic";
case INFERNO: return "inferno";
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/org/openRealmOfStars/ai/research/ResearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public void testShipDesignHandlingHuman() {
PlayerInfo info = new PlayerInfo(SpaceRace.HUMAN);
assertEquals(2, info.getShipStatList().length);
Research.handleShipDesigns(info);
assertEquals(3, info.getShipStatList().length);
int amount = info.getShipStatList().length;
info.getTechList().addTech(TechFactory.createHullTech("Small freighter", 2));
info.getTechList().addTech(TechFactory.createHullTech("Small starbase Mk1", 2));
info.getTechList().addTech(TechFactory.createCombatTech("Planetary invasion module", 2));
Research.handleShipDesigns(info);
assertEquals(7, info.getShipStatList().length);
assertEquals(amount + 4, info.getShipStatList().length);
}

@Test
Expand Down Expand Up @@ -132,11 +132,11 @@ public void testShipDesignHandlingSpy() {
info.setAttitude(Attitude.BACKSTABBING);
assertEquals(2, info.getShipStatList().length);
Research.handleShipDesigns(info);
assertEquals(3, info.getShipStatList().length);
int amount = info.getShipStatList().length;
info.getTechList().addTech(TechFactory.createHullTech("Probe", 2));
info.getTechList().addTech(TechFactory.createElectronicsTech("Espionage module Mk1", 2));
Research.handleShipDesigns(info);
assertEquals(4, info.getShipStatList().length);
assertEquals(amount + 1, info.getShipStatList().length);
}

@Test
Expand All @@ -146,10 +146,10 @@ public void testShipDesignHandlingScaurians() {
info.setAttitude(Attitude.BACKSTABBING);
assertEquals(2, info.getShipStatList().length);
Research.handleShipDesigns(info);
assertEquals(3, info.getShipStatList().length);
int amount = info.getShipStatList().length;
info.getTechList().addTech(TechFactory.createHullTech("Privateer Mk1", 5));
Research.handleShipDesigns(info);
assertEquals(4, info.getShipStatList().length);
assertEquals(amount + 1, info.getShipStatList().length);
}

@Test
Expand Down Expand Up @@ -179,15 +179,15 @@ public void testRemoveObsoleteDesigns() {
StarMap map = generator.generateStarMap(config, list);
assertEquals(2, info.getShipStatList().length);
Research.handleShipDesigns(info);
assertEquals(3, info.getShipStatList().length);
int amount = info.getShipStatList().length;
ShipDesign design = ShipGenerator.createBattleShip(info, ShipSize.SMALL,
false, false);
ShipStat stat = new ShipStat(design);
info.addShipStat(stat);
assertEquals(4, info.getShipStatList().length);
assertEquals(amount + 1, info.getShipStatList().length);
stat.setObsolete(true);
Research.removeUnusedAndObsoleteDesigns(info, map);
assertEquals(3, info.getShipStatList().length);
assertEquals(amount, info.getShipStatList().length);
}

@Test
Expand Down Expand Up @@ -341,11 +341,11 @@ public void testResearchHandlingBackstabbing() {
info.getTechList().getTechFocus(TechType.Propulsion));
assertEquals(Research.HIGH_FOCUS_LEVEL,
info.getTechList().getTechFocus(TechType.Electrics));
assertEquals(2, info.getShipStatList().length);
int amount = info.getShipStatList().length;
info.getTechList().addTech(TechFactory.createHullTech("Probe", 2));
info.getTechList().addTech(TechFactory.createElectronicsTech("Espionage module Mk1", 2));
Research.handleShipDesigns(info);
assertEquals(4, info.getShipStatList().length);
assertEquals(amount + 2, info.getShipStatList().length);
}

@Test
Expand Down

0 comments on commit 0533937

Please sign in to comment.