mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Split between unit and mapunit, created function TileMap.placeUnitNearTile which will have many uses!
This commit is contained in:
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 Unit unit;
|
||||
public MapUnit unit;
|
||||
public Vector2 position;
|
||||
public String baseTerrain;
|
||||
public String terrainFeature;
|
||||
@ -124,7 +124,7 @@ public class TileInfo
|
||||
|
||||
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;
|
||||
turnsToImprovement -= 1;
|
||||
@ -165,7 +165,7 @@ public class TileInfo
|
||||
if (roadStatus!= RoadStatus.None && !isCityCenter()) SB.append(",\r\n" + roadStatus);
|
||||
if (improvement != null) SB.append(",\r\n" + improvement);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -125,13 +125,14 @@ public class TileMap{
|
||||
}).getRandom();
|
||||
}
|
||||
|
||||
void placeUnitNearTile(Vector2 position, Unit unit){
|
||||
public void placeUnitNearTile(Vector2 position, final String unit){
|
||||
getTilesInDistance(position,1).first(new Predicate<TileInfo>() {
|
||||
@Override
|
||||
public boolean evaluate(TileInfo arg0) {
|
||||
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 hurryCostModifier;
|
||||
public int movement;
|
||||
public float currentMovement;
|
||||
boolean unbuildable; // for special units likee great people
|
||||
|
||||
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
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -47,6 +40,14 @@ public class Unit implements INamed, IConstruction{
|
||||
|
||||
@Override
|
||||
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(){
|
||||
civInfo = new CivilizationInfo();
|
||||
civInfo.tileMap.get(Vector2.Zero).unit = new Unit("Settler",2);
|
||||
civInfo.tileMap.placeUnitNearTile(Vector2.Zero,"Settler");
|
||||
|
||||
worldScreen = new WorldScreen(this);
|
||||
setWorldScreen();
|
||||
|
@ -18,6 +18,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Predicate;
|
||||
import com.unciv.civinfo.CityConstructions;
|
||||
import com.unciv.civinfo.MapUnit;
|
||||
import com.unciv.civinfo.TileInfo;
|
||||
import com.unciv.civinfo.Unit;
|
||||
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);
|
||||
|
||||
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>() {
|
||||
@Override
|
||||
public boolean evaluate(TileInfo arg0) {
|
||||
@ -400,7 +401,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
||||
if(selectedTile.unit.name.equals("Worker")) {
|
||||
String improvementButtonText = selectedTile.improvementInProgress == null ?
|
||||
"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>() {
|
||||
@Override
|
||||
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")){
|
||||
addUnitAction(tileTable, "Discover Technology",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Discover Technology",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
});
|
||||
addUnitAction(tileTable, "Construct Academy",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Construct Academy",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
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")){
|
||||
addUnitAction(tileTable, "Start Golden Age",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Start Golden Age",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
@ -445,7 +446,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
||||
update();
|
||||
}
|
||||
});
|
||||
addUnitAction(tileTable, "Construct Landmark",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Construct Landmark",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
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")){
|
||||
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
||||
addUnitAction(tileTable, "Hurry Wonder",selectedTile.unit,selectedTile.isCityCenter() &&
|
||||
addUnitAction(tileTable, "Hurry Wonder",selectedTile.isCityCenter() &&
|
||||
cityConstructions.getCurrentConstruction() instanceof Building &&
|
||||
((Building)cityConstructions.getCurrentConstruction()).isWonder,
|
||||
new ClickListener(){
|
||||
@ -469,7 +470,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
||||
update();
|
||||
}
|
||||
});
|
||||
addUnitAction(tileTable, "Construct Manufactory",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Construct Manufactory",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
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")){
|
||||
final CityConstructions cityConstructions = selectedTile.getCity().cityConstructions;
|
||||
addUnitAction(tileTable, "Conduct Trade Mission",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Conduct Trade Mission",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
@ -490,7 +491,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
|
||||
update();
|
||||
}
|
||||
});
|
||||
addUnitAction(tileTable, "Construct Customs House",selectedTile.unit,true,
|
||||
addUnitAction(tileTable, "Construct Customs House",true,
|
||||
new ClickListener(){
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
actionButton.getLabel().setFontScale(buttonScale);
|
||||
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) {
|
||||
HashSet<Vector2> hexesToReturn = new HashSet<Vector2>();
|
||||
LinqCollection<Vector2> hexesToReturn = new LinqCollection<Vector2>();
|
||||
for (int i = 0; i < distance + 1; 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.
|
||||
|
@ -149,6 +149,10 @@ public class Building extends NamedStats implements IConstruction, ICivilopedia
|
||||
constructions.builtBuildings.add(providesFreeBuilding);
|
||||
if (freeTechs != 0) UnCivGame.Current.civInfo.tech.freeTechs += freeTechs;
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user