Finished techs and buildings!

Added Science victory conditions and screen!
This commit is contained in:
Yair Morgenstern
2017-12-11 18:21:15 +02:00
parent 727aad337a
commit ede3a92c43
21 changed files with 470 additions and 89 deletions

View File

@ -28,6 +28,7 @@ public class CityBuildings
public LinqCollection<String> builtBuildings = new LinqCollection<String>();
public HashMap<String, Integer> inProgressBuildings = new HashMap<String, Integer>();
public String currentBuilding = Worker; // default starting building!
public Building getCurrentBuilding(){return getGameBuilding(currentBuilding);}
public CityInfo getCity(){return UnCivGame.Current.civInfo.tileMap.get(cityLocation).getCity(); }
public boolean isBuilt(String buildingName) { return builtBuildings.contains(buildingName); }
@ -53,6 +54,8 @@ public class CityBuildings
{
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
{
@ -68,20 +71,24 @@ public class CityBuildings
CivilizationInfo.current().notifications.add(currentBuilding+" has been built in "+getCity().name);
// Choose next building to build
currentBuilding = getBuildableBuildings().first(new Predicate<String>() {
@Override
public boolean evaluate(String arg0) {
if(arg0.equals(Settler) || arg0.equals(Worker)) return false;
return !builtBuildings.contains(arg0);
}
});
if (currentBuilding == null) currentBuilding = Worker;
chooseNextBuilding();
CivilizationInfo.current().notifications.add("Work has started on "+currentBuilding);
}
}
private void chooseNextBuilding() {
currentBuilding = getBuildableBuildings().first(new Predicate<String>() {
@Override
public boolean evaluate(String arg0) {
if(arg0.equals(Settler) || arg0.equals(Worker) || getGameBuilding(arg0).isWonder) return false;
return !builtBuildings.contains(arg0);
}
});
if (currentBuilding == null) currentBuilding = Worker;
}
public boolean canBuild(final Building building)
{
CivilizationInfo civInfo = UnCivGame.Current.civInfo;
@ -116,9 +123,19 @@ public class CityBuildings
return arg0.cityBuildings.isBuilt(building.requiredBuildingInAllCities);
}
}) ) return false;
if(building.cannotBeBuiltWith != null && isBuilt(building.cannotBeBuiltWith)) return false;
if("MustBeNextToDesert".equals(building.unique) &&
!civInfo.tileMap.getTilesInDistance(cityLocation,1).any(new Predicate<TileInfo>() {
@Override
public boolean evaluate(TileInfo arg0) {
return arg0.baseTerrain.equals("Desert");
}
}))
return false;
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;
return true;
}
@ -167,19 +184,29 @@ public class CityBuildings
return stats;
}
public int workDone(String buildingName) {
if (inProgressBuildings.containsKey(buildingName))
return inProgressBuildings.get(buildingName);
return 0;
}
public int turnsToBuilding(String buildingName)
{
int workDone = 0;
if (inProgressBuildings.containsKey(buildingName)) workDone = inProgressBuildings.get(buildingName);
float workLeft = getGameBuilding(buildingName).cost - workDone; // needs to be float so that we get the cieling properly ;)
float workLeft = getGameBuilding(buildingName).cost - workDone(buildingName); // needs to be float so that we get the cieling properly ;)
FullStats cityStats = getCity().getCityStats();
FullStats cityStats = getCity().cityStats;
int production = Math.round(cityStats.production);
if (buildingName.equals(Settler)) production += cityStats.food;
return (int) Math.ceil(workLeft / production);
}
public void purchaseBuilding(String buildingName) {
CivilizationInfo.current().civStats.gold -= getGameBuilding(buildingName).getGoldCost();
builtBuildings.add(buildingName);
if(currentBuilding.equals(buildingName)) chooseNextBuilding();
}
public String getCityProductionText(){
String result = currentBuilding;
if(!result.equals("Science") && !result.equals("Gold"))

View File

@ -4,15 +4,13 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Predicate;
import com.unciv.game.UnCivGame;
import com.unciv.models.LinqCollection;
import com.unciv.models.LinqCounter;
import com.unciv.models.LinqHashMap;
import com.unciv.models.gamebasics.Building;
import com.unciv.models.gamebasics.GameBasics;
import com.unciv.models.gamebasics.ResourceType;
import com.unciv.models.gamebasics.TileResource;
import com.unciv.models.stats.FullStats;
import java.util.ArrayList;
public class CityInfo {
public final Vector2 cityLocation;
public String name;
@ -23,6 +21,8 @@ public class CityInfo {
public int population = 1;
public int foodStored = 0;
public FullStats cityStats; // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones!
private TileMap getTileMap(){return UnCivGame.Current.civInfo.tileMap; }
public TileInfo getTile(){return getTileMap().get(cityLocation);}
@ -56,6 +56,8 @@ public class CityInfo {
name = CityNames[civInfo.cities.size()];
this.cityLocation = cityLocation;
cityBuildings = new CityBuildings(this);
if(civInfo.cities.size()==0) cityBuildings.builtBuildings.add("Palace");
civInfo.cities.add(this);
for(TileInfo tileInfo : civInfo.tileMap.getTilesInDistance(cityLocation,1)) {
tileInfo.owner = civInfo.civName;
@ -68,25 +70,22 @@ public class CityInfo {
tile.terrainFeature=null;
autoAssignWorker();
civInfo.cities.add(this);
updateCityStats();
}
public LinqHashMap<TileResource,Integer> getCityResources(){
LinqHashMap<TileResource,Integer> cityResources = new LinqHashMap<TileResource, Integer>();
public LinqCounter<TileResource> getCityResources(){
LinqCounter<TileResource> cityResources = new LinqCounter<TileResource>();
for (TileInfo tileInfo : getTilesInRange()) {
TileResource resource = tileInfo.getTileResource();
if (resource != null && (resource.improvement.equals(tileInfo.improvement) || tileInfo.isCityCenter())){
if(cityResources.containsKey(resource)) cityResources.put(resource,cityResources.get(resource)+1);
else cityResources.put(resource,1);
}
if (resource != null && (resource.improvement.equals(tileInfo.improvement) || tileInfo.isCityCenter()))
cityResources.add(resource,1);
}
// Remove resources required by buildings
for(Building building : cityBuildings.getBuiltBuildings()){
if(building.requiredResource!=null){
TileResource resource = GameBasics.TileResources.get(building.requiredResource);
if(cityResources.containsKey(resource)) cityResources.put(resource,cityResources.get(resource)-1);
else cityResources.put(resource,-1);
cityResources.add(resource,-1);
}
}
return cityResources;
@ -109,7 +108,7 @@ public class CityInfo {
return getFreePopulation() > 0;
}
public FullStats getCityStats() {
public void updateCityStats() {
FullStats stats = new FullStats();
stats.science += population;
@ -133,7 +132,7 @@ public class CityInfo {
stats.add(cityBuildings.getStats());
FullStats statPercentBonuses = cityBuildings.getStatPercentBonuses();
if(isConnectedToCapital(RoadStatus.Railroad)) statPercentBonuses.production += 25;
if(isCapital() || isConnectedToCapital(RoadStatus.Railroad)) statPercentBonuses.production += 25;
stats.food*=1+statPercentBonuses.food/100;
stats.gold*=1+statPercentBonuses.gold/100;
stats.production*=1+statPercentBonuses.production/100;
@ -143,8 +142,7 @@ public class CityInfo {
stats.gold-=cityBuildings.getMaintainanceCosts(); // this is AFTER the bonus calculation!
if(CivilizationInfo.current().getHappinessForNextTurn() < 0)
stats.food /= 4; // Reduce excess food to 1/4
return stats;
this.cityStats = stats;
}
public float getCityHappiness(){ // needs to be a separate function because we need to know the global happiness state
@ -154,8 +152,7 @@ public class CityInfo {
}
void nextTurn() {
FullStats stats = getCityStats();
FullStats stats = cityStats;
if (cityBuildings.currentBuilding.equals(CityBuildings.Settler) && stats.food > 0) {
stats.production += stats.food;
stats.food = 0;

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Predicate;
import com.unciv.game.UnCivGame;
import com.unciv.models.LinqCollection;
import com.unciv.models.LinqCounter;
import com.unciv.models.LinqHashMap;
import com.unciv.models.gamebasics.Building;
import com.unciv.models.gamebasics.GameBasics;
@ -12,7 +13,6 @@ import com.unciv.models.gamebasics.TileResource;
import com.unciv.models.stats.CivStats;
import java.util.Collection;
import java.util.HashSet;
/**
* Created by LENOVO on 10/18/2017.
@ -31,13 +31,13 @@ public class CivilizationInfo {
public LinqCollection<CityInfo> cities = new LinqCollection<CityInfo>();
public TileMap tileMap = new TileMap(20);
public LinqCounter<String> spaceshipParts = new LinqCounter<String>();
public int currentCity =0; //index!
public CivilizationInfo(){
}
public CityInfo getCurrentCity() { return cities.get(currentCity); }
public int turnsToTech(String TechName) {
@ -47,7 +47,6 @@ public class CivilizationInfo {
public void addCity(Vector2 location){
CityInfo city = new CityInfo(this,location);
if(cities.size()==1) city.cityBuildings.builtBuildings.add("Palace");
}
public CityInfo getCapital(){
@ -71,13 +70,14 @@ public class CivilizationInfo {
for(TileInfo tile : tileMap.values()) tile.nextTurn();
for (CityInfo city : cities) city.updateCityStats();
turns += 1;
}
public CivStats getStatsForNextTurn() {
CivStats statsForTurn = new CivStats();
for (CityInfo city : cities) {
statsForTurn.add(city.getCityStats());
statsForTurn.add(city.cityStats);
}
statsForTurn.happiness = getHappinessForNextTurn();
return statsForTurn;
@ -97,14 +97,10 @@ public class CivilizationInfo {
return happiness;
}
public LinqHashMap<TileResource,Integer> getCivResources(){
LinqHashMap<TileResource,Integer> civResources = new LinqHashMap<TileResource, Integer>();
for (CityInfo city : cities) {
for(TileResource resource : city.getCityResources().keySet()){
if(civResources.containsKey(resource)) civResources.put(resource,civResources.get(resource)+1);
else civResources.put(resource,1);
}
}
public LinqCounter<TileResource> getCivResources(){
LinqCounter<TileResource> civResources = new LinqCounter<TileResource>();
for (CityInfo city : cities) civResources.add(city.getCityResources());
return civResources;
}

View File

@ -2,7 +2,7 @@ package com.unciv.civinfo;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Predicate;
import com.unciv.game.HexMath;
import com.unciv.game.utils.HexMath;
import com.unciv.models.LinqCollection;
import com.unciv.models.LinqHashMap;
import com.unciv.models.gamebasics.GameBasics;

View File

@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
@ -21,13 +22,15 @@ import com.badlogic.gdx.utils.Align;
import com.unciv.civinfo.CityInfo;
import com.unciv.civinfo.TileInfo;
import com.unciv.game.pickerscreens.BuildingPickerScreen;
import com.unciv.game.pickerscreens.PickerScreen;
import com.unciv.models.gamebasics.Building;
import com.unciv.models.stats.FullStats;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class CityScreen extends CameraStageBaseScreen {
public class CityScreen extends com.unciv.game.utils.CameraStageBaseScreen {
TileInfo selectedTile = null;
float buttonScale = game.settings.buttonScale;
@ -141,12 +144,13 @@ public class CityScreen extends CameraStageBaseScreen {
public void clicked(InputEvent event, float x, float y) {
if(tileInfo.workingCity ==null && cityInfo.getFreePopulation() > 0) tileInfo.workingCity = cityInfo.name;
else if(cityInfo.name.equals(tileInfo.workingCity)) tileInfo.workingCity = null;
cityInfo.updateCityStats();
updateCityTable();
}
});
}
Vector2 positionalVector = HexMath.Hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.cityLocation));
Vector2 positionalVector = com.unciv.game.utils.HexMath.Hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.cityLocation));
int groupSize = 50;
group.setPosition(stage.getWidth()/2 + positionalVector.x*0.8f * groupSize,
stage.getHeight()/2 + positionalVector.y*0.8f * groupSize);
@ -185,8 +189,8 @@ public class CityScreen extends CameraStageBaseScreen {
}
private void updateCityTable() {
CityInfo cityInfo = game.civInfo.getCurrentCity();
FullStats stats = cityInfo.getCityStats();
final CityInfo cityInfo = game.civInfo.getCurrentCity();
FullStats stats = cityInfo.cityStats;
CityStatsTable.pad(20);
CityStatsTable.columnDefaults(0).padRight(10);
CityStatsTable.clear();
@ -198,7 +202,9 @@ public class CityScreen extends CameraStageBaseScreen {
CityStatsTable.row();
HashMap<String,String> CityStatsValues = new LinkedHashMap<String, String>();
CityStatsValues.put("Production",Math.round(stats.production) +"");
CityStatsValues.put("Production",Math.round(stats.production)
+" ("+ cityInfo.cityBuildings.workDone(cityInfo.cityBuildings.currentBuilding)
+"/"+cityInfo.cityBuildings.getCurrentBuilding().cost+")");
CityStatsValues.put("Food",Math.round(stats.food)
+" ("+cityInfo.foodStored+"/"+cityInfo.foodToNextPopulation()+")");
CityStatsValues.put("Gold",Math.round(stats.gold) +"");
@ -208,7 +214,7 @@ public class CityScreen extends CameraStageBaseScreen {
CityStatsValues.put("Population",cityInfo.getFreePopulation()+"/"+cityInfo.population);
for(String key : CityStatsValues.keySet()){
CityStatsTable.add(ImageGetter.getStatIcon(key)).align(Align.right);
CityStatsTable.add(com.unciv.game.utils.ImageGetter.getStatIcon(key)).align(Align.right);
CityStatsTable.add(new Label(CityStatsValues.get(key),skin)).align(Align.left);
CityStatsTable.row();
}
@ -229,6 +235,30 @@ public class CityScreen extends CameraStageBaseScreen {
CityStatsTable.add(buildingPickButton).colspan(2).pad(10)
.size(buildingPickButton.getWidth()*buttonScale,buildingPickButton.getHeight()*buttonScale);
// https://forums.civfanatics.com/threads/rush-buying-formula.393892/
Building building = cityInfo.cityBuildings.getCurrentBuilding();
if(!building.isWonder) {
CityStatsTable.row();
int buildingGoldCost = building.getGoldCost();
TextButton buildingBuyButton = new TextButton("Buy for \r\n"+buildingGoldCost+" gold", skin);
buildingBuyButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
cityInfo.cityBuildings.purchaseBuilding(cityInfo.cityBuildings.currentBuilding);
updateCityTable();
}
});
if(buildingGoldCost > game.civInfo.civStats.gold){
buildingBuyButton.setColor(Color.GRAY);
buildingBuyButton.setTouchable(Touchable.disabled);
}
buildingBuyButton.getLabel().setFontScale(buttonScale);
CityStatsTable.add(buildingBuyButton).colspan(2).pad(10)
.size(buildingBuyButton.getWidth() * buttonScale, buildingBuyButton.getHeight() * buttonScale);
}
CityStatsTable.setPosition(10,10);
CityStatsTable.pack();
}
@ -259,7 +289,7 @@ public class CityScreen extends CameraStageBaseScreen {
for(String key : TileStatsValues.keySet()){
if(TileStatsValues.get(key) == 0) continue; // this tile gives nothing of this stat, so why even display it?
TileTable.add(ImageGetter.getStatIcon(key)).align(Align.right);
TileTable.add(com.unciv.game.utils.ImageGetter.getStatIcon(key)).align(Align.right);
TileTable.add(new Label(Math.round(TileStatsValues.get(key))+"",skin)).align(Align.left);
TileTable.row();
}

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
public class CivilopediaScreen extends CameraStageBaseScreen {
public class CivilopediaScreen extends com.unciv.game.utils.CameraStageBaseScreen {
public CivilopediaScreen(final UnCivGame game) {
super(game);

View File

@ -0,0 +1,41 @@
package com.unciv.game;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.unciv.civinfo.CivilizationInfo;
import com.unciv.game.pickerscreens.PickerScreen;
import com.unciv.models.LinqCounter;
public class ScienceVictoryScreen extends PickerScreen {
public ScienceVictoryScreen(UnCivGame game) {
super(game);
LinqCounter<String> spaceshipParts = new LinqCounter<String>();
spaceshipParts.add(game.civInfo.spaceshipParts);
for (int i = 0; i < 3; i++) {
addPartButton("SS Booster",spaceshipParts);
}
addPartButton("SS Cockpit",spaceshipParts);
addPartButton("SS Engine",spaceshipParts);
addPartButton("SS Statis Chamber",spaceshipParts);
rightSideButton.setVisible(false);
if(!game.civInfo.getBuildingUniques().contains("ApolloProject"))
descriptionLabel.setText("You must build the Apollo Project before you can build spaceship parts!");
else descriptionLabel.setText("Apollo project is built - you may construct spaceship parts in your cities!");
}
private void addPartButton(String partName, LinqCounter<String> parts){
topTable.row();
TextButton button = new TextButton(partName,skin);
button.setTouchable(Touchable.disabled);
if (parts.get(partName)>0){
button.setColor(Color.GREEN);
parts.add(partName,-1);
}
topTable.add(button).pad(10);
}
}

View File

@ -30,14 +30,14 @@ public class TileGroup extends Group {
terrainType = tileInfo.getLastTerrain().name;
String terrainFileName = "TerrainIcons/" + terrainType.replace(' ','_') + "_(Civ5).png";
terrainImage = ImageGetter.getImageByFilename(terrainFileName);
terrainImage = com.unciv.game.utils.ImageGetter.getImageByFilename(terrainFileName);
terrainImage.setSize(50,50);
addActor(terrainImage);
}
void addPopulationIcon(){
populationImage = ImageGetter.getStatIcon("Population");
populationImage = com.unciv.game.utils.ImageGetter.getStatIcon("Population");
populationImage.moveBy(0, terrainImage.getHeight()-populationImage.getHeight()); // top left
addActor(populationImage);
}
@ -54,12 +54,12 @@ public class TileGroup extends Group {
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
terrainImage.setDrawable(new TextureRegionDrawable(com.unciv.game.utils.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";
Image image = ImageGetter.getImageByFilename(fileName);
Image image = com.unciv.game.utils.ImageGetter.getImageByFilename(fileName);
image.setSize(20,20);
image.moveBy(terrainImage.getWidth()-image.getWidth(), 0); // bottom right
resourceImage = image;
@ -67,7 +67,7 @@ public class TileGroup extends Group {
}
if (tileInfo.unit != null && unitImage == null) {
unitImage = ImageGetter.getImageByFilename("StatIcons/" + tileInfo.unit.Name + "_(Civ5).png");
unitImage = com.unciv.game.utils.ImageGetter.getImageByFilename("StatIcons/" + tileInfo.unit.Name + "_(Civ5).png");
addActor(unitImage);
unitImage.setSize(20, 20); // not moved - is at bottom left
}
@ -84,7 +84,7 @@ public class TileGroup extends Group {
if (tileInfo.improvement != null && improvementImage == null) {
improvementImage = ImageGetter.getImageByFilename("ImprovementIcons/" + tileInfo.improvement.replace(' ','_') + "_(Civ5).png");
improvementImage = com.unciv.game.utils.ImageGetter.getImageByFilename("ImprovementIcons/" + tileInfo.improvement.replace(' ','_') + "_(Civ5).png");
addActor(improvementImage);
improvementImage.setSize(20, 20);
improvementImage.moveBy(terrainImage.getWidth()-improvementImage.getWidth(),
@ -101,11 +101,11 @@ public class TileGroup extends Group {
if (neighbor == tileInfo || neighbor.roadStatus == RoadStatus.None) continue;
if (roadImages.containsKey(neighbor.position.toString())) continue;
Image image = ImageGetter.getImageByFilename("TerrainIcons/road.png");
Image image = com.unciv.game.utils.ImageGetter.getImageByFilename("TerrainIcons/road.png");
roadImages.put(neighbor.position.toString(), image);
Vector2 relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position);
Vector2 relativeWorldPosition = HexMath.Hex2WorldCoords(relativeHexPosition);
Vector2 relativeWorldPosition = com.unciv.game.utils.HexMath.Hex2WorldCoords(relativeHexPosition);
// This is some crazy voodoo magic so I'll explain.
image.moveBy(25, 25); // Move road to center of tile

View File

@ -4,9 +4,10 @@ import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Json;
import com.unciv.civinfo.CityInfo;
import com.unciv.civinfo.CivilizationInfo;
import com.unciv.civinfo.Unit;
import com.unciv.game.pickerscreens.GameSaver;
import com.unciv.game.utils.GameSaver;
import com.unciv.models.gamebasics.BasicHelp;
import com.unciv.models.gamebasics.Building;
import com.unciv.models.gamebasics.GameBasics;
@ -31,6 +32,9 @@ public class UnCivGame extends Game {
if(GameSaver.GetSave("Autosave").exists()) {
try {
GameSaver.LoadGame(this, "Autosave");
for (CityInfo city : this.civInfo.cities) {
if(city.cityStats == null) city.updateCityStats();
}
} catch(Exception ex){ // silent fail if we can't read the autosave
startNewGame();
}

View File

@ -8,7 +8,6 @@ import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
@ -17,12 +16,11 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Predicate;
import com.unciv.civinfo.TileInfo;
import com.unciv.game.pickerscreens.GameSaver;
import com.unciv.game.pickerscreens.ImprovementPickerScreen;
import com.unciv.game.pickerscreens.TechPickerScreen;
import com.unciv.game.utils.*;
import com.unciv.models.LinqHashMap;
import com.unciv.models.gamebasics.GameBasics;
import com.unciv.models.gamebasics.TileImprovement;
@ -32,7 +30,7 @@ import com.unciv.models.stats.FullStats;
import java.util.HashMap;
import java.util.HashSet;
public class WorldScreen extends CameraStageBaseScreen {
public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
TileInfo selectedTile = null;
@ -80,7 +78,6 @@ public class WorldScreen extends CameraStageBaseScreen {
}
private void addNotificationsList() {
// NotificationsTable.setBackground(TileTable.getBackground());
stage.addActor(NotificationsTable);
}
private void updateNotificationsList() {
@ -128,8 +125,18 @@ public class WorldScreen extends CameraStageBaseScreen {
});
OptionsTable.add(StartNewGameButton).pad(10);
OptionsTable.row();
TextButton OpenScienceVictoryScreen = new TextButton("Science victory status",skin);
OpenScienceVictoryScreen.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(new ScienceVictoryScreen(game));
}
});
OptionsTable.add(OpenScienceVictoryScreen).pad(10);
OptionsTable.row();
TextButton closeButton = new TextButton("Close",skin);
closeButton.addListener(new ClickListener(){
@Override
@ -251,7 +258,7 @@ public class WorldScreen extends CameraStageBaseScreen {
});
Vector2 positionalVector = HexMath.Hex2WorldCoords(tileInfo.position);
Vector2 positionalVector = com.unciv.game.utils.HexMath.Hex2WorldCoords(tileInfo.position);
int groupSize = 50;
group.setPosition(stage.getWidth() / 2 + positionalVector.x * 0.8f * groupSize,
stage.getHeight() / 2 + positionalVector.y * 0.8f * groupSize);
@ -323,7 +330,7 @@ public class WorldScreen extends CameraStageBaseScreen {
for(String key : TileStatsValues.keySet()){
if(TileStatsValues.get(key) == 0) continue; // this tile gives nothing of this stat, so why even display it?
TileTable.add(ImageGetter.getStatIcon(key)).align(Align.right);
TileTable.add(com.unciv.game.utils.ImageGetter.getStatIcon(key)).align(Align.right);
TileTable.add(new Label(Math.round(TileStatsValues.get(key))+"",skin)).align(Align.left);
TileTable.row();
}
@ -434,7 +441,7 @@ public class WorldScreen extends CameraStageBaseScreen {
// tiles adjacent to city tiles
for(TileInfo tileInfo : game.civInfo.tileMap.values())
if(game.civInfo.civName.equals(tileInfo.owner))
for(Vector2 adjacentLocation : HexMath.GetAdjacentVectors(tileInfo.position))
for(Vector2 adjacentLocation : com.unciv.game.utils.HexMath.GetAdjacentVectors(tileInfo.position))
ViewableVectorStrings.add(adjacentLocation.toString());
// Tiles within 2 tiles of units
@ -445,7 +452,7 @@ public class WorldScreen extends CameraStageBaseScreen {
return arg0.unit !=null;
}
}))
for(Vector2 vector : HexMath.GetVectorsInDistance(tile.position,2))
for(Vector2 vector : com.unciv.game.utils.HexMath.GetVectorsInDistance(tile.position,2))
ViewableVectorStrings.add(vector.toString());
for(String string : ViewableVectorStrings)

View File

@ -8,7 +8,6 @@ import com.unciv.civinfo.CityInfo;
import com.unciv.civinfo.TileInfo;
public class WorldTileGroup extends TileGroup {
WorldTileGroup(TileInfo tileInfo) {
@ -29,7 +28,7 @@ public class WorldTileGroup extends TileGroup {
if (tileInfo.owner != null && hexagon == null) {
hexagon = ImageGetter.getImageByFilename("TerrainIcons/Hexagon.png");
hexagon = com.unciv.game.utils.ImageGetter.getImageByFilename("TerrainIcons/Hexagon.png");
float imageScale = terrainImage.getWidth() * 1.3f / hexagon.getWidth();
hexagon.setScale(imageScale);
hexagon.setPosition((getWidth() - hexagon.getWidth() * imageScale) / 2,

View File

@ -8,16 +8,16 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.unciv.game.CameraStageBaseScreen;
import com.unciv.game.utils.CameraStageBaseScreen;
import com.unciv.game.UnCivGame;
public class PickerScreen extends CameraStageBaseScreen {
TextButton closeButton;
Label descriptionLabel;
TextButton rightSideButton;
protected Label descriptionLabel;
protected TextButton rightSideButton;
float screenSplit = 0.85f;
Table topTable;
protected Table topTable;
SplitPane splitPane;

View File

@ -1,4 +1,4 @@
package com.unciv.game;
package com.unciv.game.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
@ -13,14 +13,15 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.unciv.game.UnCivGame;
import java.util.HashMap;
public class CameraStageBaseScreen implements Screen {
protected UnCivGame game;
protected Stage stage;
protected Skin skin = new Skin(Gdx.files.internal("skin/flat-earth-ui.json"));
public UnCivGame game;
public Stage stage;
public Skin skin = new Skin(Gdx.files.internal("skin/flat-earth-ui.json"));
static Batch batch = new SpriteBatch();

View File

@ -1,4 +1,4 @@
package com.unciv.game.pickerscreens;
package com.unciv.game.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

View File

@ -1,4 +1,4 @@
package com.unciv.game;
package com.unciv.game.utils;
import com.badlogic.gdx.math.Vector2;
import com.unciv.models.LinqCollection;

View File

@ -1,4 +1,4 @@
package com.unciv.game;
package com.unciv.game.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

View File

@ -0,0 +1,23 @@
package com.unciv.models;
import java.util.LinkedHashMap;
public class LinqCounter<K> extends LinkedHashMap<K,Integer> {
public Integer get(Object key){ // don't return null if empty
if(containsKey(key)) return super.get(key);
else return 0;
}
public void add(K key, int value){
if(!containsKey(key)) put(key,value);
else put(key,get(key)+value);
if(get(key)==0) remove(key); // No objects of this sort left, no need to count
}
public void add(LinqCounter<K> other){
for (K key : other.keySet()) {
add(key,other.get(key));
}
}
}

View File

@ -7,3 +7,4 @@ public class LinqHashMap <K,V> extends LinkedHashMap<K,V> {
return new LinqCollection<V>(super.values());
}
}

View File

@ -15,18 +15,20 @@ public class Building extends NamedStats implements ICivilopedia {
public int cost;
public int maintainance = 0;
public FullStats percentStatBonus = new FullStats();
//public Func<CityInfo,FullStats> GetFlatBonusStats;
public int hurryCostModifier; // Extra cost percentage when purchasing
public boolean isWonder = false;
public boolean resourceBoostingBuilding = false;
public String requiredBuilding;
public String requiredBuildingInAllCities;
public String requiredResource;
public String cannotBeBuiltWith;
// Uniques
public String providesFreeBuilding;
public int freeTechs;
public String unique; // for wonders which have individual functions that are totally unique
/**
* The bonus stats that a resource gets when this building is built
*/
@ -54,6 +56,10 @@ public class Building extends NamedStats implements ICivilopedia {
stringBuilder.append(description + "\r\n" + stats);
return stringBuilder.toString();
}
public int getGoldCost(){
return (int)( Math.pow(30 * cost,0.75) * (1 + hurryCostModifier/100) / 10 ) * 10;
}
}