mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Split between unit and mapunit, created function TileMap.placeUnitNearTile which will have many uses!
This commit is contained in:
parent
98dbe3b844
commit
c274367ab1
7
core/src/com/unciv/civinfo/MapUnit.java
Normal file
7
core/src/com/unciv/civinfo/MapUnit.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.unciv.civinfo;
|
||||||
|
|
||||||
|
public class MapUnit{
|
||||||
|
public String name;
|
||||||
|
public int maxMovement;
|
||||||
|
public float currentMovement;
|
||||||
|
}
|
@ -14,7 +14,7 @@ import java.text.DecimalFormat;
|
|||||||
|
|
||||||
public class TileInfo
|
public class TileInfo
|
||||||
{
|
{
|
||||||
public Unit unit;
|
public MapUnit unit;
|
||||||
public Vector2 position;
|
public Vector2 position;
|
||||||
public String baseTerrain;
|
public String baseTerrain;
|
||||||
public String terrainFeature;
|
public String terrainFeature;
|
||||||
@ -124,7 +124,7 @@ public class TileInfo
|
|||||||
|
|
||||||
public void nextTurn()
|
public void nextTurn()
|
||||||
{
|
{
|
||||||
if(unit !=null) unit.currentMovement = unit.movement;
|
if(unit !=null) unit.currentMovement = unit.maxMovement;
|
||||||
|
|
||||||
if (improvementInProgress == null || unit ==null || !unit.name.equals("Worker")) return;
|
if (improvementInProgress == null || unit ==null || !unit.name.equals("Worker")) return;
|
||||||
turnsToImprovement -= 1;
|
turnsToImprovement -= 1;
|
||||||
@ -165,7 +165,7 @@ public class TileInfo
|
|||||||
if (roadStatus!= RoadStatus.None && !isCityCenter()) SB.append(",\r\n" + roadStatus);
|
if (roadStatus!= RoadStatus.None && !isCityCenter()) SB.append(",\r\n" + roadStatus);
|
||||||
if (improvement != null) SB.append(",\r\n" + improvement);
|
if (improvement != null) SB.append(",\r\n" + improvement);
|
||||||
if (improvementInProgress != null) SB.append(",\r\n" + improvementInProgress +" in "+this.turnsToImprovement +" turns");
|
if (improvementInProgress != null) SB.append(",\r\n" + improvementInProgress +" in "+this.turnsToImprovement +" turns");
|
||||||
if (unit !=null) SB.append(",\r\n" + unit.name + "("+ new DecimalFormat("0.#").format(unit.currentMovement)+"/"+ unit.movement +")");
|
if (unit !=null) SB.append(",\r\n" + unit.name + "("+ new DecimalFormat("0.#").format(unit.currentMovement)+"/"+ unit.maxMovement+")");
|
||||||
return SB.toString();
|
return SB.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,13 +125,14 @@ public class TileMap{
|
|||||||
}).getRandom();
|
}).getRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
void placeUnitNearTile(Vector2 position, Unit unit){
|
public void placeUnitNearTile(Vector2 position, final String unit){
|
||||||
getTilesInDistance(position,1).first(new Predicate<TileInfo>() {
|
getTilesInDistance(position,1).first(new Predicate<TileInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(TileInfo arg0) {
|
public boolean evaluate(TileInfo arg0) {
|
||||||
return arg0.unit==null;
|
return arg0.unit==null;
|
||||||
}
|
}
|
||||||
}).unit = unit; // And if there's none, then kill me.
|
}).unit = GameBasics.Units.get(unit).getMapUnit(); // And if there's none, then kill me.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,17 +9,10 @@ public class Unit implements INamed, IConstruction{
|
|||||||
public int cost;
|
public int cost;
|
||||||
public int hurryCostModifier;
|
public int hurryCostModifier;
|
||||||
public int movement;
|
public int movement;
|
||||||
public float currentMovement;
|
|
||||||
boolean unbuildable; // for special units likee great people
|
boolean unbuildable; // for special units likee great people
|
||||||
|
|
||||||
public Unit(){} // for json parsing, we need to have a default constructor
|
public Unit(){} // for json parsing, we need to have a default constructor
|
||||||
|
|
||||||
public Unit(String name, int maxMovement) {
|
|
||||||
this.name = name;
|
|
||||||
this.movement = maxMovement;
|
|
||||||
currentMovement = maxMovement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -47,6 +40,14 @@ public class Unit implements INamed, IConstruction{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postBuildEvent(CityConstructions construction) {
|
public void postBuildEvent(CityConstructions construction) {
|
||||||
UnCivGame.Current.civInfo.tileMap.placeUnitNearTile(construction.cityLocation,new Unit(name,movement));
|
UnCivGame.Current.civInfo.tileMap.placeUnitNearTile(construction.cityLocation,name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapUnit getMapUnit(){
|
||||||
|
MapUnit unit = new MapUnit();
|
||||||
|
unit.name=name;
|
||||||
|
unit.maxMovement=movement;
|
||||||
|
unit.currentMovement=movement;
|
||||||
|
return unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class UnCivGame extends Game {
|
|||||||
|
|
||||||
public void startNewGame(){
|
public void startNewGame(){
|
||||||
civInfo = new CivilizationInfo();
|
civInfo = new CivilizationInfo();
|
||||||
civInfo.tileMap.get(Vector2.Zero).unit = new Unit("Settler",2);
|
civInfo.tileMap.placeUnitNearTile(Vector2.Zero,"Settler");
|
||||||
|
|
||||||
worldScreen = new WorldScreen(this);
|
worldScreen = new WorldScreen(this);
|
||||||
setWorldScreen();
|
setWorldScreen();
|
||||||
|
@ -18,6 +18,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
|||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.Predicate;
|
import com.badlogic.gdx.utils.Predicate;
|
||||||
import com.unciv.civinfo.CityConstructions;
|
import com.unciv.civinfo.CityConstructions;
|
||||||
|
import com.unciv.civinfo.MapUnit;
|
||||||
import com.unciv.civinfo.TileInfo;
|
import com.unciv.civinfo.TileInfo;
|
||||||
import com.unciv.civinfo.Unit;
|
import com.unciv.civinfo.Unit;
|
||||||
import com.unciv.game.pickerscreens.ImprovementPickerScreen;
|
import com.unciv.game.pickerscreens.ImprovementPickerScreen;
|
||||||
@ -378,7 +379,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
.size(moveUnitButton.getWidth() * buttonScale, moveUnitButton.getHeight() * buttonScale);
|
.size(moveUnitButton.getWidth() * buttonScale, moveUnitButton.getHeight() * buttonScale);
|
||||||
|
|
||||||
if(selectedTile.unit.name.equals("Settler")) {
|
if(selectedTile.unit.name.equals("Settler")) {
|
||||||
addUnitAction(tileTable, "Found City", selectedTile.unit,
|
addUnitAction(tileTable, "Found City",
|
||||||
!game.civInfo.tileMap.getTilesInDistance(selectedTile.position, 2).any(new Predicate<TileInfo>() {
|
!game.civInfo.tileMap.getTilesInDistance(selectedTile.position, 2).any(new Predicate<TileInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(TileInfo arg0) {
|
public boolean evaluate(TileInfo arg0) {
|
||||||
@ -400,7 +401,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
if(selectedTile.unit.name.equals("Worker")) {
|
if(selectedTile.unit.name.equals("Worker")) {
|
||||||
String improvementButtonText = selectedTile.improvementInProgress == null ?
|
String improvementButtonText = selectedTile.improvementInProgress == null ?
|
||||||
"Construct\r\nimprovement" : selectedTile.improvementInProgress +"\r\nin progress";
|
"Construct\r\nimprovement" : selectedTile.improvementInProgress +"\r\nin progress";
|
||||||
addUnitAction(tileTable,improvementButtonText,selectedTile.unit, !selectedTile.isCityCenter() ||
|
addUnitAction(tileTable,improvementButtonText, !selectedTile.isCityCenter() ||
|
||||||
GameBasics.TileImprovements.linqValues().any(new Predicate<TileImprovement>() {
|
GameBasics.TileImprovements.linqValues().any(new Predicate<TileImprovement>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(TileImprovement arg0) {
|
public boolean evaluate(TileImprovement arg0) {
|
||||||
@ -415,7 +416,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(selectedTile.unit.name.equals("Great Scientist")){
|
if(selectedTile.unit.name.equals("Great Scientist")){
|
||||||
addUnitAction(tileTable, "Discover Technology",selectedTile.unit,true,
|
addUnitAction(tileTable, "Discover Technology",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -424,7 +425,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
game.setScreen(new TechPickerScreen(game,true));
|
game.setScreen(new TechPickerScreen(game,true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addUnitAction(tileTable, "Construct Academy",selectedTile.unit,true,
|
addUnitAction(tileTable, "Construct Academy",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -436,7 +437,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(selectedTile.unit.name.equals("Great Artist")){
|
if(selectedTile.unit.name.equals("Great Artist")){
|
||||||
addUnitAction(tileTable, "Start Golden Age",selectedTile.unit,true,
|
addUnitAction(tileTable, "Start Golden Age",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -445,7 +446,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addUnitAction(tileTable, "Construct Landmark",selectedTile.unit,true,
|
addUnitAction(tileTable, "Construct Landmark",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -458,7 +459,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
|
|
||||||
if(selectedTile.unit.name.equals("Great Engineer")){
|
if(selectedTile.unit.name.equals("Great Engineer")){
|
||||||
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
||||||
addUnitAction(tileTable, "Hurry Wonder",selectedTile.unit,selectedTile.isCityCenter() &&
|
addUnitAction(tileTable, "Hurry Wonder",selectedTile.isCityCenter() &&
|
||||||
cityConstructions.getCurrentConstruction() instanceof Building &&
|
cityConstructions.getCurrentConstruction() instanceof Building &&
|
||||||
((Building)cityConstructions.getCurrentConstruction()).isWonder,
|
((Building)cityConstructions.getCurrentConstruction()).isWonder,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@ -469,7 +470,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addUnitAction(tileTable, "Construct Manufactory",selectedTile.unit,true,
|
addUnitAction(tileTable, "Construct Manufactory",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -481,7 +482,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
}
|
}
|
||||||
if(selectedTile.unit.name.equals("Great Merchant")){
|
if(selectedTile.unit.name.equals("Great Merchant")){
|
||||||
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
||||||
addUnitAction(tileTable, "Conduct Trade Mission",selectedTile.unit,true,
|
addUnitAction(tileTable, "Conduct Trade Mission",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -490,7 +491,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addUnitAction(tileTable, "Construct Customs House",selectedTile.unit,true,
|
addUnitAction(tileTable, "Construct Customs House",true,
|
||||||
new ClickListener(){
|
new ClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
@ -507,7 +508,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
|||||||
tileTable.setPosition(stage.getWidth()-10- tileTable.getWidth(), 10);
|
tileTable.setPosition(stage.getWidth()-10- tileTable.getWidth(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addUnitAction(Table tileTable, String actionText, Unit unit, boolean canAct, ClickListener action) {
|
private void addUnitAction(Table tileTable, String actionText, boolean canAct, ClickListener action) {
|
||||||
TextButton actionButton = new TextButton(actionText, skin);
|
TextButton actionButton = new TextButton(actionText, skin);
|
||||||
actionButton.getLabel().setFontScale(buttonScale);
|
actionButton.getLabel().setFontScale(buttonScale);
|
||||||
actionButton.addListener(action);
|
actionButton.addListener(action);
|
||||||
|
@ -74,4 +74,3 @@ public class WorldTileGroup extends TileGroup {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ public class HexMath
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static LinqCollection<Vector2> GetVectorsInDistance(Vector2 origin, int distance) {
|
public static LinqCollection<Vector2> GetVectorsInDistance(Vector2 origin, int distance) {
|
||||||
HashSet<Vector2> hexesToReturn = new HashSet<Vector2>();
|
LinqCollection<Vector2> hexesToReturn = new LinqCollection<Vector2>();
|
||||||
for (int i = 0; i < distance + 1; i++) {
|
for (int i = 0; i < distance + 1; i++) {
|
||||||
hexesToReturn.addAll(GetVectorsAtDistance(origin, i));
|
hexesToReturn.addAll(GetVectorsAtDistance(origin, i));
|
||||||
}
|
}
|
||||||
return new LinqCollection<Vector2>(hexesToReturn);
|
return hexesToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
@ -149,6 +149,10 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
|||||||
constructions.builtBuildings.add(providesFreeBuilding);
|
constructions.builtBuildings.add(providesFreeBuilding);
|
||||||
if (freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += freeTechs;
|
if (freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += freeTechs;
|
||||||
if("EmpireEntersGoldenAge".equals(unique)) CivilizationInfo.current().enterGoldenAge();
|
if("EmpireEntersGoldenAge".equals(unique)) CivilizationInfo.current().enterGoldenAge();
|
||||||
|
if("WorkerConstruction".equals(unique)){
|
||||||
|
CivilizationInfo.current().tileMap.placeUnitNearTile(constructions.cityLocation,"Worker");
|
||||||
|
CivilizationInfo.current().tileMap.placeUnitNearTile(constructions.cityLocation,"Worker");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user