Load game does not crash when there are notifications

Automated workers no longer complete improvements in a single turn
City screen does not display building catagories which are irrelevant
This commit is contained in:
Yair Morgenstern 2018-01-19 13:20:42 +02:00
parent d8a7c379e7
commit 80e3d16895
6 changed files with 89 additions and 66 deletions

View file

@ -68,7 +68,7 @@ public class CityInfo {
TileInfo tile = getTile();
tile.workingCity = this.name;
tile.roadStatus = RoadStatus.Railroad;
if("Forest".equals(tile.terrainFeature) || "Jungle".equals(tile.terrainFeature) || "Marsh".equals(tile.terrainFeature))
if(new Linq<String>("Forest","Jungle","Marsh").contains(tile.terrainFeature))
tile.terrainFeature=null;
population.autoAssignWorker();

View file

@ -2,6 +2,7 @@ package com.unciv.logic.civilization;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Predicate;
import com.sun.jmx.remote.security.NotificationAccessController;
import com.unciv.logic.city.CityInfo;
import com.unciv.logic.map.RoadStatus;
import com.unciv.logic.map.TileInfo;
@ -36,15 +37,7 @@ public class CivilizationInfo {
public GreatPersonManager greatPeople = new GreatPersonManager();
public int turns = 1;
public class Notification{
public final String text;
public final Vector2 location;
Notification(String text, Vector2 location) {
this.text = text;
this.location = location;
}
}
public Linq<Notification> notifications = new Linq<Notification>();
public void addNotification(String text, Vector2 location){
notifications.add(new Notification(text,location));

View file

@ -0,0 +1,15 @@
package com.unciv.logic.civilization;
import com.badlogic.gdx.math.Vector2;
public class Notification{
public String text;
public Vector2 location;
Notification(){}
Notification(String text, Vector2 location) {
this.text = text;
this.location = location;
}
}

View file

@ -24,8 +24,9 @@ public class MapUnit{
if(currentMovement!=0) doAction(gotTo);
return;
}
if ("automation".equals(action)) {doAutomatedAction(tile);return;}
if(name.equals("Worker") && tile.improvementInProgress!=null) workOnImprovement(tile);
if ("automation".equals(action)) doAutomatedAction(tile);
}
@ -88,9 +89,13 @@ public class MapUnit{
public void doAutomatedAction(TileInfo tile){
TileInfo toWork = findTileToWork(tile);
if(toWork==null) return; // Don't know what to do. Sorry.
if(toWork!=tile) tile = headTowards(tile.position,toWork.position);
if(toWork == tile && tile.improvementInProgress==null) tile.startWorkingOnImprovement(chooseImprovement(tile));
doAction(tile);
if(toWork!=tile) {
tile = headTowards(tile.position, toWork.position);
doAction(tile);
return;
}
if(tile.improvementInProgress == null) tile.startWorkingOnImprovement(chooseImprovement(tile));
workOnImprovement(tile);
}
private String chooseImprovement(final TileInfo tile){

View file

@ -148,57 +148,64 @@ public class CityScreen extends CameraStageBaseScreen {
else Others.add(building);
}
Label label = new Label("Wonders",skin);
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for(Building building:Wonders) BuildingsTable.add(new Label(building.name,skin)).pad(5).row();
label = new Label("Specialist Buildings",skin);
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for(Building building:SpecialistBuildings) {
BuildingsTable.add(new Label(building.name, skin)).pad(5);
Table specialists = new Table();
specialists.row().size(20).pad(5);
if (!getCity().population.buildingsSpecialists.containsKey(building.name))
getCity().population.buildingsSpecialists.put(building.name, new FullStats());
FullStats currentBuildingSpecialists = getCity().population.buildingsSpecialists.get(building.name);
for (int i = 0; i < building.specialistSlots.production; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationBrown.png", building.name,
currentBuildingSpecialists.production > i, new FullStats() {{
production = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.science; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationBlue.png", building.name,
currentBuildingSpecialists.science > i, new FullStats() {{
science = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.culture; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationPurple.png", building.name,
currentBuildingSpecialists.culture > i, new FullStats() {{
culture = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.gold; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationYellow.png", building.name,
currentBuildingSpecialists.gold > i, new FullStats() {{
gold = 1;
}}));
}
BuildingsTable.add(specialists).row();
if(!Wonders.isEmpty()) {
Label label = new Label("Wonders", skin);
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for (Building building : Wonders)
BuildingsTable.add(new Label(building.name, skin)).pad(5).row();
}
label = new Label("Buildings",skin);
if(!SpecialistBuildings.isEmpty()) {
Label label = new Label("Specialist Buildings", skin);
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for (Building building : SpecialistBuildings) {
BuildingsTable.add(new Label(building.name, skin)).pad(5);
Table specialists = new Table();
specialists.row().size(20).pad(5);
if (!getCity().population.buildingsSpecialists.containsKey(building.name))
getCity().population.buildingsSpecialists.put(building.name, new FullStats());
FullStats currentBuildingSpecialists = getCity().population.buildingsSpecialists.get(building.name);
for (int i = 0; i < building.specialistSlots.production; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationBrown.png", building.name,
currentBuildingSpecialists.production > i, new FullStats() {{
production = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.science; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationBlue.png", building.name,
currentBuildingSpecialists.science > i, new FullStats() {{
science = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.culture; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationPurple.png", building.name,
currentBuildingSpecialists.culture > i, new FullStats() {{
culture = 1;
}}));
}
for (int i = 0; i < building.specialistSlots.gold; i++) {
specialists.add(getSpecialistIcon("StatIcons/populationYellow.png", building.name,
currentBuildingSpecialists.gold > i, new FullStats() {{
gold = 1;
}}));
}
BuildingsTable.add(specialists).row();
}
}
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for(Building building:Others) BuildingsTable.add(new Label(building.name,skin)).pad(5).row();
if(!Others.isEmpty()) {
Label label = new Label("Buildings", skin);
label.setFontScale(1.5f);
label.setColor(Color.GREEN);
BuildingsTable.add(label).pad(5).row();
for (Building building : Others)
BuildingsTable.add(new Label(building.name, skin)).pad(5).row();
}
BuildingsTable.pack();
}

View file

@ -16,6 +16,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Predicate;
import com.unciv.logic.civilization.CivilizationInfo;
import com.unciv.logic.civilization.Notification;
import com.unciv.logic.map.TileInfo;
import com.unciv.ui.pickerscreens.PolicyPickerScreen;
import com.unciv.ui.pickerscreens.TechPickerScreen;
@ -49,6 +50,7 @@ public class WorldScreen extends CameraStageBaseScreen {
Table optionsTable = new Table();
Table notificationsTable = new Table();
ScrollPane notificationsScroll = new ScrollPane(notificationsTable);
TextButton selectIdleUnitButton;
public WorldScreen() {
@ -57,7 +59,7 @@ public class WorldScreen extends CameraStageBaseScreen {
addTiles();
stage.addActor(tileTable);
Drawable tileTableBackground = com.unciv.ui.utils.ImageGetter.getDrawable("skin/tileTableBackground.png")
Drawable tileTableBackground = ImageGetter.getDrawable("skin/tileTableBackground.png")
.tint(new Color(0x004085bf));
tileTableBackground.setMinHeight(0);
tileTableBackground.setMinWidth(0);
@ -66,14 +68,12 @@ public class WorldScreen extends CameraStageBaseScreen {
//notificationsTable.background(ImageGetter.getSingleColorDrawable(new Color(0x004085bf)));
TextureRegionDrawable civBackground = com.unciv.ui.utils.ImageGetter.getDrawable("skin/civTableBackground.png");
TextureRegionDrawable civBackground = ImageGetter.getDrawable("skin/civTableBackground.png");
civTable.setBackground(civBackground.tint(new Color(0x004085bf)));
stage.addActor(civTable);
stage.addActor(techButton);
ScrollPane notificationsScroll = new ScrollPane(notificationsTable);
notificationsScroll.setSize(stage.getWidth() / 3, stage.getHeight() / 3);
stage.addActor(notificationsScroll);
addSelectIdleUnitButton();
update();
@ -145,13 +145,13 @@ public class WorldScreen extends CameraStageBaseScreen {
private void updateNotificationsList() {
notificationsTable.clearChildren();
for (final CivilizationInfo.Notification notification : game.civInfo.notifications) {
for (final Notification notification : game.civInfo.notifications) {
Label label = new Label(notification.text, skin);
label.setColor(Color.WHITE);
label.setFontScale(1.2f);
Table minitable = new Table();
minitable.background(com.unciv.ui.utils.ImageGetter.getDrawable("skin/civTableBackground.png")
minitable.background(ImageGetter.getDrawable("skin/civTableBackground.png")
.tint(new Color(0x004085bf)));
minitable.add(label).pad(5);
@ -168,6 +168,9 @@ public class WorldScreen extends CameraStageBaseScreen {
notificationsTable.row();
}
notificationsTable.pack();
notificationsScroll.setSize(stage.getWidth() / 3,
Math.min(notificationsTable.getHeight(),stage.getHeight() / 3));
}
public void update() {