diff --git a/core/src/com/unciv/civinfo/CityBuildings.java b/core/src/com/unciv/civinfo/CityBuildings.java index 8723d50934..2726048021 100644 --- a/core/src/com/unciv/civinfo/CityBuildings.java +++ b/core/src/com/unciv/civinfo/CityBuildings.java @@ -3,6 +3,7 @@ package com.unciv.civinfo; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Predicate; import com.unciv.game.UnCivGame; +import com.unciv.game.VictoryScreen; import com.unciv.models.LinqCollection; import com.unciv.models.gamebasics.Building; import com.unciv.models.gamebasics.GameBasics; @@ -47,20 +48,37 @@ public class CityBuildings if (currentBuilding == null) return; if(currentBuilding.equals("Gold")) {cityStats.gold+=cityStats.production/3; return;} if(currentBuilding.equals("Science")) {cityStats.science+=cityStats.production/3; return;} + + + Building gameBuilding = getGameBuilding(currentBuilding); + + // Let's try to remove the building from the city, and seee if we can still build it (weneed to remove because of wonders etc. + String saveCurrentBuilding = currentBuilding; + currentBuilding = null; + if(!canBuild(gameBuilding)){ + // We can't build this building anymore! (Wonder has been built / resource is gone / etc.) + CivilizationInfo.current().notifications.add("Cannot continue work on "+saveCurrentBuilding); + chooseNextBuilding(); + gameBuilding = getGameBuilding(currentBuilding); + } + else currentBuilding = saveCurrentBuilding; + if (!inProgressBuildings.containsKey(currentBuilding)) inProgressBuildings.put(currentBuilding, 0); inProgressBuildings.put(currentBuilding, inProgressBuildings.get(currentBuilding) + Math.round(cityStats.production)); - if (inProgressBuildings.get(currentBuilding) >= getGameBuilding(currentBuilding).cost) + if (inProgressBuildings.get(currentBuilding) >= gameBuilding.cost) { if (currentBuilding.equals(Worker) || currentBuilding.equals(Settler)) UnCivGame.Current.civInfo.tileMap.get(cityLocation).unit = new Unit(currentBuilding,2); - else if("SpaceshipPart".equals(getGameBuilding(currentBuilding).unique)) - CivilizationInfo.current().spaceshipParts.add(currentBuilding,1); + else if("SpaceshipPart".equals(gameBuilding.unique)) { + CivilizationInfo.current().scienceVictory.currentParts.add(currentBuilding, 1); + if(CivilizationInfo.current().scienceVictory.unconstructedParts().isEmpty()) + UnCivGame.Current.setScreen(new VictoryScreen(UnCivGame.Current)); + } else { builtBuildings.add(currentBuilding); - Building gameBuilding = getGameBuilding(currentBuilding); if (gameBuilding.providesFreeBuilding != null && !builtBuildings.contains(gameBuilding.providesFreeBuilding)) builtBuildings.add(gameBuilding.providesFreeBuilding); if (gameBuilding.freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += gameBuilding.freeTechs; @@ -70,10 +88,7 @@ public class CityBuildings CivilizationInfo.current().notifications.add(currentBuilding+" has been built in "+getCity().name); - // Choose next building to build chooseNextBuilding(); - - CivilizationInfo.current().notifications.add("Work has started on "+currentBuilding); } } @@ -87,6 +102,8 @@ public class CityBuildings } }); if (currentBuilding == null) currentBuilding = Worker; + + CivilizationInfo.current().notifications.add("Work has started on "+currentBuilding); } public boolean canBuild(final Building building) @@ -135,7 +152,11 @@ public class CityBuildings if(building.requiredResource!=null && !civInfo.getCivResources().keySet().contains(GameBasics.TileResources.get(building.requiredResource))) return false; // Only checks if exists, doesn't check amount - todo - if(building.unique.equals("SpaceshipPart") && !civInfo.getBuildingUniques().contains("ApolloProgram")) return false; + + if(building.unique.equals("SpaceshipPart")){ + if(!civInfo.getBuildingUniques().contains("ApolloProgram")) return false; + if(civInfo.scienceVictory.requiredParts.get(building.name)==0) return false; // Don't need to build any more of these! + } return true; } diff --git a/core/src/com/unciv/civinfo/CivilizationInfo.java b/core/src/com/unciv/civinfo/CivilizationInfo.java index 3d735ac742..ac9c33d6f4 100644 --- a/core/src/com/unciv/civinfo/CivilizationInfo.java +++ b/core/src/com/unciv/civinfo/CivilizationInfo.java @@ -31,7 +31,7 @@ public class CivilizationInfo { public LinqCollection cities = new LinqCollection(); public TileMap tileMap = new TileMap(20); - public LinqCounter spaceshipParts = new LinqCounter(); + public ScienceVictory scienceVictory = new ScienceVictory(); public int currentCity =0; //index! @@ -119,3 +119,13 @@ public class CivilizationInfo { } } +class ScienceVictory{ + public LinqCounter requiredParts = new LinqCounter(); + public LinqCounter currentParts = new LinqCounter(); + + public LinqCounter unconstructedParts() { + LinqCounter counter = requiredParts.clone(); + counter.remove(currentParts); + return counter; + } +} \ No newline at end of file diff --git a/core/src/com/unciv/game/ScienceVictoryScreen.java b/core/src/com/unciv/game/ScienceVictoryScreen.java index 87d1d5d11a..460481a5f2 100644 --- a/core/src/com/unciv/game/ScienceVictoryScreen.java +++ b/core/src/com/unciv/game/ScienceVictoryScreen.java @@ -39,3 +39,5 @@ public class ScienceVictoryScreen extends PickerScreen { topTable.add(button).pad(10); } } + + diff --git a/core/src/com/unciv/game/VictoryScreen.java b/core/src/com/unciv/game/VictoryScreen.java new file mode 100644 index 0000000000..d94a877af4 --- /dev/null +++ b/core/src/com/unciv/game/VictoryScreen.java @@ -0,0 +1,33 @@ +package com.unciv.game; + +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.unciv.game.utils.CameraStageBaseScreen; + +import javax.xml.soap.Text; + +public class VictoryScreen extends CameraStageBaseScreen{ + + public VictoryScreen(final UnCivGame game) { + super(game); + + Label label = new Label("Congrendulation!\r\nYou have won!!!!!",skin); + label.setFontScale(5); + label.setPosition((stage.getWidth()-label.getWidth())/2 , (stage.getHeight()-label.getHeight())/2 ); + stage.addActor(label); + + + TextButton newGameButton = new TextButton("New game!",skin); + newGameButton.addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y) { + game.startNewGame(); + } + }); + newGameButton.setPosition((stage.getWidth()-newGameButton.getWidth())/2 , 10); + } + + +} diff --git a/core/src/com/unciv/models/LinqCounter.java b/core/src/com/unciv/models/LinqCounter.java index 5f5f24f82a..fb5a172f94 100644 --- a/core/src/com/unciv/models/LinqCounter.java +++ b/core/src/com/unciv/models/LinqCounter.java @@ -20,4 +20,17 @@ public class LinqCounter extends LinkedHashMap { add(key,other.get(key)); } } + + public void remove(LinqCounter other){ + for (K key : other.keySet()) { + add(key,-other.get(key)); + } + } + + @Override + public LinqCounter clone() { + LinqCounter newCounter = new LinqCounter(); + newCounter.add(this); + return newCounter; + } }