diff --git a/core/src/com/unciv/civinfo/CityBuildings.java b/core/src/com/unciv/civinfo/CityBuildings.java index 66fd8b1192..5b2be4a79a 100644 --- a/core/src/com/unciv/civinfo/CityBuildings.java +++ b/core/src/com/unciv/civinfo/CityBuildings.java @@ -145,7 +145,7 @@ public class CityBuildings stats.science += getCity().getBuildingUniques().count(new Predicate() { @Override public boolean evaluate(String arg0) { - return arg0.equals("SciencePer2Pop"); + return "SciencePer2Pop".equals(arg0); } }) * getCity().population/2; // Library and public school unique (not actualy unique, though...hmm) return stats; diff --git a/core/src/com/unciv/civinfo/CityInfo.java b/core/src/com/unciv/civinfo/CityInfo.java index a81e5baa98..acd1716d57 100644 --- a/core/src/com/unciv/civinfo/CityInfo.java +++ b/core/src/com/unciv/civinfo/CityInfo.java @@ -281,6 +281,11 @@ public class CityInfo { public String GetBy(Building arg0) { return arg0.unique; } + }).where(new Predicate() { + @Override + public boolean evaluate(String arg0) { + return arg0!=null; + } }); } diff --git a/core/src/com/unciv/civinfo/CivilizationTech.java b/core/src/com/unciv/civinfo/CivilizationTech.java index 0eb92a1e32..383f1dcc3b 100644 --- a/core/src/com/unciv/civinfo/CivilizationTech.java +++ b/core/src/com/unciv/civinfo/CivilizationTech.java @@ -5,11 +5,12 @@ import com.unciv.models.gamebasics.Technology; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; public class CivilizationTech{ public int freeTechs = 0; - public ArrayList techsResearched = new ArrayList(); + public HashSet techsResearched = new HashSet(); /* When moving towards a certain tech, the user doesn't have to manually pick every one. */ public ArrayList techsToResearch = new ArrayList(); public HashMap techsInProgress = new HashMap(); diff --git a/core/src/com/unciv/game/HexMath.java b/core/src/com/unciv/game/HexMath.java index d07e3a3064..e74b2e4bb8 100644 --- a/core/src/com/unciv/game/HexMath.java +++ b/core/src/com/unciv/game/HexMath.java @@ -46,22 +46,31 @@ public class HexMath return vectors; } - public static LinqCollection GetVectorsInDistance(Vector2 origin, int distance){ + public static ArrayList GetVectorsAtDistance(Vector2 origin, int distance){ + ArrayList vectors = new ArrayList(); + Vector2 Current = origin.cpy().sub(distance,distance); // start at 6 o clock + for (int i = 0; i < distance; i++) { // From 6 to 8 + vectors.add(Current.cpy()); + vectors.add(origin.cpy().scl(2).sub(Current)); // Get vector on other side of cloick + Current.add(1,0); + } + for (int i = 0; i < distance; i++) { // 8 to 10 + vectors.add(Current.cpy()); + vectors.add(origin.cpy().scl(2).sub(Current)); // Get vector on other side of cloick + Current.add(1,1); + } + for (int i = 0; i < distance; i++) { // 10 to 12 + vectors.add(Current.cpy()); + vectors.add(origin.cpy().scl(2).sub(Current)); // Get vector on other side of cloick + Current.add(1,1); + }; + return vectors; + } + + public static LinqCollection GetVectorsInDistance(Vector2 origin, int distance) { HashSet hexesToReturn = new HashSet(); - HashSet oldHexes; - HashSet newHexes = new HashSet(); - hexesToReturn.add(origin); - newHexes.add(origin); - for (int i = 0; i < distance; i++) { - oldHexes = newHexes; - newHexes = new HashSet(); - for (Vector2 vector : oldHexes) { - for (Vector2 adjacentVector : GetAdjacentVectors(vector)){ - if(hexesToReturn.contains(adjacentVector)) continue; - hexesToReturn.add(adjacentVector); - newHexes.add(adjacentVector); - } - } + for (int i = 0; i < distance + 1; i++) { + hexesToReturn.addAll(GetVectorsAtDistance(origin, i)); } return new LinqCollection(hexesToReturn); } @@ -69,19 +78,9 @@ public class HexMath public static int GetDistance(Vector2 origin, Vector2 destination){ // Yes, this is a dumb implementation. But I can't be arsed to think of a better one right now, other stuff to do. int distance = 0; while(true){ - if(GetVectorsInDistance(origin,distance).contains(destination)) return distance; + if(GetVectorsAtDistance(origin,distance).contains(destination)) return distance; distance++; } } -// public static boolean IsWithinDistance(Vector2 a, Vector2 b, int distance){ -// return GetVectorsInDistance(a,distance).contains(b); -// Vector2 distanceVector = a.sub(b); -// if(distanceVector.x<0) distanceVector = new Vector2(-distanceVector.x,-distanceVector.y); -// -// int distance = (int) Math.abs(distanceVector.x); -// distanceVector = distanceVector.sub(distanceVector.x,distanceVector.x); // Zero X f distance, then we'll calculate Y -// distance += Math.abs(distanceVector.y); -// return distance; -// } } diff --git a/core/src/com/unciv/game/TileGroup.java b/core/src/com/unciv/game/TileGroup.java index 9dcee9bc77..69dcd4b4b1 100644 --- a/core/src/com/unciv/game/TileGroup.java +++ b/core/src/com/unciv/game/TileGroup.java @@ -6,16 +6,15 @@ import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.ui.Container; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; -import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.unciv.civinfo.CivilizationInfo; import com.unciv.civinfo.RoadStatus; import com.unciv.civinfo.TileInfo; -import com.unciv.models.LinqCollection; import com.unciv.models.LinqHashMap; public class TileGroup extends Group { Image terrainImage; + String terrainType; Image resourceImage; Image unitImage; Image improvementImage; @@ -29,7 +28,8 @@ public class TileGroup extends Group { TileGroup(TileInfo tileInfo){ this.tileInfo = tileInfo; - String terrainFileName = "TerrainIcons/" + tileInfo.getLastTerrain().name.replace(' ','_') + "_(Civ5).png"; + terrainType = tileInfo.getLastTerrain().name; + String terrainFileName = "TerrainIcons/" + terrainType.replace(' ','_') + "_(Civ5).png"; terrainImage = ImageGetter.getImageByFilename(terrainFileName); terrainImage.setSize(50,50); addActor(terrainImage); @@ -50,8 +50,12 @@ public class TileGroup extends Group { void update() { - String terrainFileName ="TerrainIcons/" + tileInfo.getLastTerrain().name.replace(' ','_') + "_(Civ5).png"; - terrainImage.setDrawable(new TextureRegionDrawable(ImageGetter.textureRegionByFileName.get(terrainFileName))); // In case we e.g. removed a jungle + + if(!terrainType.equals(tileInfo.getLastTerrain().name)) { + terrainType = tileInfo.getLastTerrain().name; + String terrainFileName = "TerrainIcons/" + terrainType.replace(' ', '_') + "_(Civ5).png"; + terrainImage.setDrawable(new TextureRegionDrawable(ImageGetter.textureRegionByFileName.get(terrainFileName))); // In case we e.g. removed a jungle + } if (tileInfo.hasViewableResource() && resourceImage == null) { // Need to add the resource image! String fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png"; diff --git a/core/src/com/unciv/game/WorldScreen.java b/core/src/com/unciv/game/WorldScreen.java index 02a406f4a2..d82ffc2ae1 100644 --- a/core/src/com/unciv/game/WorldScreen.java +++ b/core/src/com/unciv/game/WorldScreen.java @@ -94,8 +94,10 @@ public class WorldScreen extends CameraStageBaseScreen { } public void update(){ - if(game.civInfo.tech.freeTechs!=0) - game.setScreen(new TechPickerScreen(game,true)); + if(game.civInfo.tech.freeTechs!=0) { + game.setScreen(new TechPickerScreen(game, true)); + return; + } updateTechButton(); updateTileTable(); updateTiles(); @@ -416,16 +418,12 @@ public class WorldScreen extends CameraStageBaseScreen { TileTable.pack(); -// TileTable.setBackground(getTableBackground(TileTable.getWidth(),TileTable.getHeight())); - TileTable.setPosition(stage.getWidth()-10- TileTable.getWidth(), 10); } private void updateTiles() { for (WorldTileGroup WG : tileGroups.linqValues()) WG.update(this); - - if(unitTile!=null) return; // While we're in "unit move" mode, no tiles but the tiles the unit can move to will be "visible" // YES A TRIPLE FOR, GOT PROBLEMS WITH THAT? diff --git a/core/src/com/unciv/game/pickerscreens/TechPickerScreen.java b/core/src/com/unciv/game/pickerscreens/TechPickerScreen.java index 698c099fe2..821e478a04 100644 --- a/core/src/com/unciv/game/pickerscreens/TechPickerScreen.java +++ b/core/src/com/unciv/game/pickerscreens/TechPickerScreen.java @@ -31,10 +31,7 @@ public class TechPickerScreen extends PickerScreen { public TechPickerScreen(final UnCivGame game) { super(game); - Technology[][] techMatrix = new Technology[10][10]; // Divided into columns, then rows - for (int i = 0; i < techMatrix.length; i++) { - techMatrix[i] = new Technology[10]; - } + Technology[][] techMatrix = new Technology[12][10]; // Divided into columns, then rows for (Technology technology : GameBasics.Technologies.linqValues()) { techMatrix[technology.column.columnNumber-1][technology.row - 1] = technology; @@ -58,9 +55,10 @@ public class TechPickerScreen extends PickerScreen { topTable.add(TB); } } - SetButtonsInfo(); } + setButtonsInfo(); + rightSideButton.setText("Pick a tech"); rightSideButton.setTouchable(Touchable.disabled); rightSideButton.setColor(Color.GRAY); @@ -76,12 +74,13 @@ public class TechPickerScreen extends PickerScreen { } else civTech.techsToResearch = techsToResearch; game.setWorldScreen(); + game.worldScreen.update(); dispose(); } }); } - public void SetButtonsInfo() { + public void setButtonsInfo() { for (String techName : techNameToButton.keySet()) { TextButton TB = techNameToButton.get(techName); TB.getStyle().checkedFontColor = Color.BLACK; @@ -91,7 +90,7 @@ public class TechPickerScreen extends PickerScreen { else TB.setColor(Color.GRAY); TB.setChecked(false); - TB.setText(techName); + StringBuilder text = new StringBuilder(techName); if (selectedTech != null) { Technology thisTech = GameBasics.Technologies.get(techName); @@ -100,14 +99,15 @@ public class TechPickerScreen extends PickerScreen { TB.setColor(TB.getColor().lerp(Color.LIGHT_GRAY, 0.5f)); } - if (thisTech.prerequisites.contains(selectedTech.name)) TB.setText("*" + techName); - else if (selectedTech.prerequisites.contains(techName)) TB.setText(techName + "*"); + if (thisTech.prerequisites.contains(selectedTech.name)) text.insert(0, "*"); + else if (selectedTech.prerequisites.contains(techName)) text.append("*"); } if (techsToResearch.contains(techName)) { - TB.setText(TB.getText() + " (" + techsToResearch.indexOf(techName) + ")"); + text.append(" (").append(techsToResearch.indexOf(techName)).append(")"); } - if(!civTech.isResearched(techName)) TB.setText(TB.getText() + "\r\n" + game.civInfo.turnsToTech(techName) + " turns"); + if(!civTech.isResearched(techName)) text.append("\r\n"+game.civInfo.turnsToTech(techName) + " turns"); + TB.setText(text.toString()); } } @@ -120,7 +120,7 @@ public class TechPickerScreen extends PickerScreen { rightSideButton.setText("Research"); rightSideButton.setTouchable(Touchable.disabled); rightSideButton.setColor(Color.GRAY); - SetButtonsInfo(); + setButtonsInfo(); return; } @@ -148,7 +148,7 @@ public class TechPickerScreen extends PickerScreen { } rightSideButton.setText("Research \r\n" + techsToResearch.get(0)); - SetButtonsInfo(); + setButtonsInfo(); } private void selectTechnologyForFreeTech(Technology tech){ diff --git a/core/src/com/unciv/models/gamebasics/Technology.java b/core/src/com/unciv/models/gamebasics/Technology.java index b5b0f05fdf..2511cb3ae3 100644 --- a/core/src/com/unciv/models/gamebasics/Technology.java +++ b/core/src/com/unciv/models/gamebasics/Technology.java @@ -1,6 +1,7 @@ package com.unciv.models.gamebasics; import java.util.ArrayList; +import java.util.HashSet; public class Technology { @@ -8,7 +9,7 @@ public class Technology public String description; public int cost; - public ArrayList prerequisites = new ArrayList(); + public HashSet prerequisites = new HashSet(); public TechColumn column; // The column that this tech is in the tech tree public int row;