Skip to content

Commit

Permalink
#666 Fixes issue when building where moved to JSON files.
Browse files Browse the repository at this point in the history
Fixes JUnits and old BuildingFactory could use case insensetive names on
buildings. Now all techs and building names need to match.
testResearchWiki() JUnit should reveal this.
  • Loading branch information
tuomount committed Dec 16, 2023
1 parent 1a65df8 commit add8d9e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/openRealmOfStars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ public void changeGameState(final GameState newState) {
* @param level Which tech level
* @return String of tech info in markdown format
*/
@SuppressWarnings("null")
public static String printTech(final String[] techNames,
final TechType type, final int level) {
StringBuilder sb = new StringBuilder();
Expand All @@ -2115,6 +2116,9 @@ public static String printTech(final String[] techNames,
tech.getComponent());
sb.append(i + 1);
sb.append(". ");
if (comp == null) {
ErrorLogger.log("Hull not found:" + tech.getImprovement());
}
sb.append(comp.toString());
sb.append("\n\n");
noPrint = false;
Expand All @@ -2123,6 +2127,9 @@ public static String printTech(final String[] techNames,
Building build = BuildingFactory.createByName(tech.getImprovement());
sb.append(i + 1);
sb.append(". ");
if (build == null) {
ErrorLogger.log("Building not found:" + tech.getImprovement());
}
sb.append(build.getFullDescription());
sb.append("\n\n");
noPrint = false;
Expand All @@ -2132,6 +2139,9 @@ public static String printTech(final String[] techNames,
SpaceRace.HUMAN);
sb.append(i + 1);
sb.append(". ");
if (hull == null) {
ErrorLogger.log("Hull not found:" + tech.getImprovement());
}
sb.append(hull.toString());
sb.append("\n\n");
noPrint = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private TechFactory() {
*/
public static final String[] IMPROVEMENT_TECH_LEVEL9_NAMES = {
"Hydropodic farming center", "Nanobot mining center",
"Nanobot manufacturing center", "Research Matrix",
"Nanobot manufacturing center", "Research matrix",
"Planetary furnace"};
/**
* Planetary Improvement rare tech names for level 9
Expand All @@ -371,7 +371,7 @@ private TechFactory() {
* Planetary Improvement tech names for level 10
*/
public static final String[] IMPROVEMENT_TECH_LEVEL10_NAMES = {
"Neural research center", "Super AI Center", "Replicator center" };
"Neural research center", "Super AI center", "Replicator center" };

/**
* Propulsion tech names for level 1
Expand Down Expand Up @@ -1004,7 +1004,7 @@ public static Tech createImprovementTech(final String name, final int level) {
|| techName.startsWith("Research center")
|| techName.startsWith("New technology center")
|| techName.startsWith("Neural research center")
|| techName.startsWith("Super AI Center")) {
|| techName.startsWith("Super AI center")) {
tech.setIcon(Icons.getIconByName(Icons.ICON_RESEARCH));
} else if (techName.startsWith("Orbital lift")) {
tech.setIcon(Icons.getIconByName(Icons.ICON_ORBITAL_ELEVATOR));
Expand Down Expand Up @@ -1037,7 +1037,7 @@ public static Tech createImprovementTech(final String name, final int level) {
tech.setSpaceRaces(SpaceRace.MECHIONS, SpaceRace.SYNTHDROIDS);
tech.setTradeable(false);
} else if (techName.startsWith("Collective research center")
|| techName.startsWith("Research Matrix")) {
|| techName.startsWith("Research matrix")) {
tech.setIcon(Icons.getIconByName(Icons.ICON_RESEARCH));
tech.setExcludeList(false);
tech.setSpaceRaces(SpaceRace.REBORGIANS, SpaceRace.MECHIONS,
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/openRealmOfStars/player/tech/TechList.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public int getNumberOfScientificAchievements() {
if (tech.getImprovement() != null) {
Building building = BuildingFactory.createByName(
tech.getImprovement());
if (building.getScientificAchievement()) {
if (building != null && building.getScientificAchievement()) {
result++;
}
if (tech.getName().equals("Artificial planet")) {
Expand Down Expand Up @@ -974,7 +974,7 @@ public void updateResearchPointByTurn(final int totalResearchPoints,
* @param tech Tech
* @param info PlayerInfo
*/
private void newTechTutorial(final Tech tech, final PlayerInfo info) {
private static void newTechTutorial(final Tech tech, final PlayerInfo info) {
var techComponent = tech.getComponent();
var techHull = tech.getHull();
var techType = tech.getType();
Expand Down Expand Up @@ -1090,7 +1090,8 @@ private void newTechTutorial(final Tech tech, final PlayerInfo info) {
* @param tutorialIdx tutorial index
* @param info PlayerInfo
*/
private void showTutorial(final int tutorialIdx, final PlayerInfo info) {
private static void showTutorial(final int tutorialIdx,
final PlayerInfo info) {
var tutorialText = Game.getTutorial().showTutorialText(tutorialIdx);
if (tutorialText != null) {
var msg = new Message(MessageType.INFORMATION, tutorialText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,13 +1627,13 @@ public void testHomarianHandling5PopulationClanLab() {
planet.setPlanetOwner(1, info);
planet.setWorkers(Planet.METAL_MINERS, 5);
PlanetHandling.handlePlanetPopulation(planet, info, 0);
assertEquals(1, planet.getWorkers(Planet.PRODUCTION_WORKERS));
assertEquals(1, planet.getWorkers(Planet.METAL_MINERS));
assertEquals(0, planet.getWorkers(Planet.PRODUCTION_WORKERS));
assertEquals(0, planet.getWorkers(Planet.METAL_MINERS));
assertEquals(2, planet.getWorkers(Planet.FOOD_FARMERS));
assertEquals(0, planet.getWorkers(Planet.RESEARCH_SCIENTIST));
assertEquals(2, planet.getWorkers(Planet.RESEARCH_SCIENTIST));
assertEquals(1, planet.getWorkers(Planet.CULTURE_ARTIST));
assertEquals(1, planet.getTotalProduction(Planet.PRODUCTION_RESEARCH));
assertEquals(2, planet.getTotalProduction(Planet.PRODUCTION_PRODUCTION));
assertEquals(1, planet.getTotalProduction(Planet.PRODUCTION_PRODUCTION));
assertEquals(7, planet.getTotalProduction(Planet.PRODUCTION_FOOD));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,40 @@ public void testAncientFactory() {
assertEquals(false, building.isBroadcaster());
}

@Test
@Category(org.openRealmOfStars.UnitTest.class)
public void testSuperAiCenter() {
Building building = BuildingFactory.createByName("Super AI center");
assertEquals("Super AI center", building.getName());
assertEquals(4, building.getReseBonus());
assertEquals(0, building.getCredBonus());
assertEquals(0, building.getCultBonus());
assertEquals(0, building.getMineBonus());
assertEquals(1, building.getFactBonus());
assertEquals(0, building.getFarmBonus());
assertEquals(0, building.getFleetCapacityBonus());
assertEquals(0, building.getHappiness());
assertEquals(1.00, building.getMaintenanceCost(), 0.05);
assertEquals(false, building.isBroadcaster());
}

@Test
@Category(org.openRealmOfStars.UnitTest.class)
public void testResearchMatix() {
Building building = BuildingFactory.createByName("Research matrix");
assertEquals("Research matrix", building.getName());
assertEquals(3, building.getReseBonus());
assertEquals(0, building.getCredBonus());
assertEquals(0, building.getCultBonus());
assertEquals(0, building.getMineBonus());
assertEquals(0, building.getFactBonus());
assertEquals(0, building.getFarmBonus());
assertEquals(0, building.getFleetCapacityBonus());
assertEquals(2, building.getHappiness());
assertEquals(0.25, building.getMaintenanceCost(), 0.05);
assertEquals(false, building.isBroadcaster());
}

@Test
@Category(org.openRealmOfStars.UnitTest.class)
public void testAncientTemple() {
Expand Down

0 comments on commit add8d9e

Please sign in to comment.