mirror of https://github.com/FreeCol/freecol.git
Bugfixes and some new features:
- Added effects for printing press/newspaper - Units may now be trained at schoolhouse/college/university.
This commit is contained in:
parent
13b1d1baa8
commit
ec2c7d907a
|
@ -116,6 +116,7 @@ public final class InfoPanel extends JPanel {
|
|||
unitLabel.setIcon(null);
|
||||
unitNameLabel.setText("");
|
||||
unitMovesLabel.setText("");
|
||||
unitToolsLabel.setText("");
|
||||
}
|
||||
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
|
|
|
@ -65,7 +65,25 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
SHOP = 2,
|
||||
FACTORY = 3;
|
||||
|
||||
private static final String[][] buildingNames = {{"Town hall", null, null}, {"Carpenter's house", "Lumber mill", null}, {"Blacksmith's house", "Blacksmith's shop", "Iron works"}, {"Tobacconist's house", "Tobacconist's shop", "Cigar factory"}, {"Weaver's house", "Weaver's shop", "Textile mill"}, {"Distiller's house", "Rum distillery", "Rum factory"}, {"Fur trader's house", "Fur trading post", "Fur factory"}, {"Stockade", "Fort", "Fortress"}, {"Armory", "Magazine", "Arsenal"}, {"Docks", "Drydock", "Shipyard"}, {"Schoolhouse", "College", "University"}, {"Warehouse", "Warehouse expansion", null}, {"Stables", null, null}, {"Church", "Cathedral", null}, {"Printing press", "Newspaper", null}, {"Custom house", null, null}};
|
||||
//private static final String[][] buildingNames = {{"Town hall", null, null}, {"Carpenter's house", "Lumber mill", null}, {"Blacksmith's house", "Blacksmith's shop", "Iron works"}, {"Tobacconist's house", "Tobacconist's shop", "Cigar factory"}, {"Weaver's house", "Weaver's shop", "Textile mill"}, {"Distiller's house", "Rum distillery", "Rum factory"}, {"Fur trader's house", "Fur trading post", "Fur factory"}, {"Stockade", "Fort", "Fortress"}, {"Armory", "Magazine", "Arsenal"}, {"Docks", "Drydock", "Shipyard"}, {"Schoolhouse", "College", "University"}, {"Warehouse", "Warehouse expansion", null}, {"Stables", null, null}, {"Church", "Cathedral", null}, {"Printing press", "Newspaper", null}, {"Custom house", null, null}};
|
||||
private static final String[][] buildingNames = {
|
||||
{"Town hall", null, null},
|
||||
{"Carpenter's house", "Lumber mill", null},
|
||||
{"Blacksmith's house", "Blacksmith's shop", "Iron works"},
|
||||
{"Tobacconist's house", "Tobacconist's shop", "Cigar factory"},
|
||||
{"Weaver's house", "Weaver's shop", "Textile mill"},
|
||||
{"Distiller's house", "Rum distillery", "Rum factory"},
|
||||
{"Fur trader's house", "Fur trading post", "Fur factory"},
|
||||
{"Schoolhouse", "College", "University"},
|
||||
{"Armory", "Magazine", "Arsenal"},
|
||||
{"Church", "Cathedral", null},
|
||||
{"Stockade", "Fort", "Fortress"},
|
||||
{"Warehouse", "Warehouse expansion", null},
|
||||
{"Stables", null, null},
|
||||
{"Docks", "Drydock", "Shipyard"},
|
||||
{"Printing press", "Newspaper", null},
|
||||
{"Custom house", null, null}
|
||||
};
|
||||
|
||||
// Sets the maximum number of units in one building (will become a non-constant later):
|
||||
private static final int MAX_UNITS = 3;
|
||||
|
@ -303,6 +321,8 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
if (type == STOCKADE || type == DOCK || type == WAREHOUSE ||
|
||||
type == STABLES || type == PRINTING_PRESS || type == CUSTOM_HOUSE) {
|
||||
return 0;
|
||||
} else if (type == SCHOOLHOUSE) {
|
||||
return getLevel();
|
||||
} else {
|
||||
return MAX_UNITS;
|
||||
}
|
||||
|
@ -333,6 +353,14 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (getType() == SCHOOLHOUSE && (getLevel() < Unit.getSkillLevel(((Unit) locatable).getType())
|
||||
|| ((Unit) locatable).getType() == Unit.INDIAN_CONVERT
|
||||
|| ((Unit) locatable).getType() == Unit.FREE_COLONIST
|
||||
|| ((Unit) locatable).getType() == Unit.INDENTURED_SERVANT
|
||||
|| ((Unit) locatable).getType() == Unit.PETTY_CRIMINAL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -427,6 +455,71 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
return units.iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the best unit to train for the given unit type.
|
||||
*
|
||||
* @param unitType The unit type to train for.
|
||||
* @return The <code>Unit</code>.
|
||||
*/
|
||||
private Unit getUnitToTrain(int unitType) {
|
||||
Unit bestUnit = null;
|
||||
int bestScore = 0;
|
||||
|
||||
Iterator i = colony.getUnitIterator();
|
||||
while (i.hasNext()) {
|
||||
Unit unit = (Unit) i.next();
|
||||
|
||||
if (unit.getTrainingType() != -1 && unit.getNeededTurnsOfTraining() <= unit.getTurnsOfTraining()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unit.getType() == Unit.FREE_COLONIST && unit.getTrainingType() == unitType) {
|
||||
if (bestUnit == null || unit.getTurnsOfTraining() > bestUnit.getTurnsOfTraining()) {
|
||||
bestUnit = unit;
|
||||
bestScore = 5;
|
||||
}
|
||||
} else if (unit.getType() == Unit.FREE_COLONIST && unit.getTurnsOfTraining() == 0) {
|
||||
if (bestScore < 4) {
|
||||
bestUnit = unit;
|
||||
bestScore = 4;
|
||||
}
|
||||
} else if (unit.getType() == Unit.INDENTURED_SERVANT) {
|
||||
if (bestScore < 3) {
|
||||
bestUnit = unit;
|
||||
bestScore = 3;
|
||||
}
|
||||
} else if (unit.getType() == Unit.PETTY_CRIMINAL) {
|
||||
if (bestScore < 2) {
|
||||
bestUnit = unit;
|
||||
bestScore = 2;
|
||||
}
|
||||
} else if (unit.getType() == Unit.FREE_COLONIST && getTeacher(unitType) == null) {
|
||||
if (bestScore < 1) {
|
||||
bestUnit = unit;
|
||||
bestScore = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestUnit;
|
||||
}
|
||||
|
||||
|
||||
private Unit getTeacher(int unitType) {
|
||||
Iterator i = colony.getUnitIterator();
|
||||
while (i.hasNext()) {
|
||||
Unit unit = (Unit) i.next();
|
||||
|
||||
if (unit.getType() == unitType) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this <code>Building</code> for a new turn.
|
||||
*/
|
||||
|
@ -439,6 +532,40 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
|
||||
if ((level == NOT_BUILT) && (type != CHURCH)) return; // Don't do anything if the building does not exist.
|
||||
|
||||
if (type == SCHOOLHOUSE) {
|
||||
Iterator i = getUnitIterator();
|
||||
while (i.hasNext()) {
|
||||
Unit teacher = (Unit) i.next();
|
||||
Unit student = getUnitToTrain(teacher.getType());
|
||||
|
||||
if (student != null) {
|
||||
if (student.getTrainingType() != teacher.getType() && student.getTrainingType() != Unit.FREE_COLONIST) {
|
||||
student.setTrainingType(teacher.getType());
|
||||
student.setTurnsOfTraining(0);
|
||||
}
|
||||
|
||||
student.setTurnsOfTraining(student.getTurnsOfTraining() + ((colony.getSoL() == 100) ? 2 : 1));
|
||||
|
||||
if (student.getTurnsOfTraining() >= student.getNeededTurnsOfTraining()) {
|
||||
if (student.getType() == Unit.INDENTURED_SERVANT) {
|
||||
student.setType(Unit.FREE_COLONIST);
|
||||
} else if (student.getType() == Unit.PETTY_CRIMINAL) {
|
||||
student.setType(Unit.INDENTURED_SERVANT);
|
||||
} else {
|
||||
student.setType(student.getTrainingType());
|
||||
}
|
||||
|
||||
// TODO: Add message about unit beeing trained.
|
||||
|
||||
student.setTrainingType(-1);
|
||||
student.setTurnsOfTraining(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Figure out what's produced here and what it requires to do so.
|
||||
switch(type) {
|
||||
case BLACKSMITH:
|
||||
|
@ -504,6 +631,11 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
goodsOutput = (goodsInput * 3) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (goodsOutputType == Goods.BELLS) {
|
||||
goodsOutput += goodsOutput * colony.getBuilding(Building.PRINTING_PRESS).getLevel();
|
||||
}
|
||||
|
||||
if (goodsOutput <= 0) return;
|
||||
|
||||
// Actually produce the goods.
|
||||
|
|
|
@ -110,6 +110,10 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
private Location location;
|
||||
|
||||
private int workType; // What type of goods this unit produces in its occupation.
|
||||
|
||||
private int turnsOfTraining = 0;
|
||||
private int trainingType = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Initiate a new <code>Unit</code> of a specified type with the state set
|
||||
|
@ -195,7 +199,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
/*public Unit(Game game, Location location, Player owner, int type, int movesLeft, int s, int id) {
|
||||
super(game);
|
||||
|
||||
unitContainer = new UnitContainer(game, this);
|
||||
unitContainer = new UnitContainer(game, this);
|
||||
|
||||
this.location = location;
|
||||
location.add(this);
|
||||
|
@ -269,6 +273,112 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of turns this unit has to train to
|
||||
* become the current {@link #getTrainingType training type}.
|
||||
*
|
||||
* @return The turns of training needed to become the current
|
||||
* training type, or <code>Integer.MAX_VALUE</code> if
|
||||
* if no training type is specified.
|
||||
* @see #getTrainingType
|
||||
* @see #getTurnsOfTraining
|
||||
*/
|
||||
public int getNeededTurnsOfTraining() {
|
||||
if (trainingType != -1) {
|
||||
return 2 + getSkillLevel(trainingType);
|
||||
} else {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the skill level.
|
||||
*/
|
||||
public static int getSkillLevel(int unitType) {
|
||||
switch (unitType) {
|
||||
case FREE_COLONIST:
|
||||
return 0;
|
||||
case EXPERT_FISHERMAN:
|
||||
case EXPERT_FARMER:
|
||||
case EXPERT_FUR_TRAPPER:
|
||||
case EXPERT_SILVER_MINER:
|
||||
case EXPERT_LUMBER_JACK:
|
||||
case EXPERT_ORE_MINER:
|
||||
case MASTER_CARPENTER:
|
||||
case SEASONED_SCOUT:
|
||||
case HARDY_PIONEER:
|
||||
return 1;
|
||||
case MASTER_SUGAR_PLANTER:
|
||||
case MASTER_COTTON_PLANTER:
|
||||
case MASTER_TOBACCO_PLANTER:
|
||||
case MASTER_GUNSMITH:
|
||||
case MASTER_FUR_TRADER:
|
||||
case MASTER_BLACKSMITH:
|
||||
case MASTER_DISTILLER:
|
||||
case MASTER_WEAVER:
|
||||
case MASTER_TOBACCONIST:
|
||||
case VETERAN_SOLDIER:
|
||||
return 2;
|
||||
case FIREBRAND_PREACHER:
|
||||
case ELDER_STATESMAN:
|
||||
case JESUIT_MISSIONARY:
|
||||
return 3;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of turns this unit has been training.
|
||||
*
|
||||
* @see #setTurnsOfTraining
|
||||
* @see #getTrainingType
|
||||
* @see #getNeededTurnsOfTraining
|
||||
*/
|
||||
public int getTurnsOfTraining() {
|
||||
return turnsOfTraining;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the number of turns this unit has been training.
|
||||
* @see #getNeededTurnsOfTraining
|
||||
*/
|
||||
public void setTurnsOfTraining(int turnsOfTraining) {
|
||||
this.turnsOfTraining = turnsOfTraining;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the unit type this <code>Unit</code> is training for.
|
||||
*
|
||||
* @see #getTurnsOfTraining
|
||||
* @see #setTrainingType
|
||||
*/
|
||||
public int getTrainingType() {
|
||||
return trainingType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the unit type this <code>Unit</code> is training for.
|
||||
* Use <code>-1</code> for no type at all.
|
||||
*
|
||||
* @see #getTurnsOfTraining
|
||||
* @see #getTrainingType
|
||||
*/
|
||||
public void setTrainingType(int trainingType) {
|
||||
if (getType() == PETTY_CRIMINAL || getType() == INDENTURED_SERVANT) {
|
||||
this.trainingType = FREE_COLONIST;
|
||||
} else {
|
||||
this.trainingType = trainingType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the type of goods this unit is producing in its current occupation.
|
||||
* @return The type of goods this unit would produce.
|
||||
|
@ -290,7 +400,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
workType = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the type of a move made in a specified direction.
|
||||
*
|
||||
|
@ -481,7 +591,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* @exception IllegalStateException If the carrier is on another tile than this unit.
|
||||
*/
|
||||
public void boardShip(Unit carrier) {
|
||||
if (getTile() == carrier.getTile()) {
|
||||
if (getTile() == carrier.getTile() && carrier.getState() != TO_EUROPE && carrier.getState() != TO_AMERICA) {
|
||||
setLocation(carrier);
|
||||
setState(SENTRY);
|
||||
} else {
|
||||
|
@ -499,14 +609,13 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* @exception ClassCastException If not this unit is located on a ship.
|
||||
*/
|
||||
public void leaveShip() {
|
||||
Location l = ((Unit) getLocation()).getLocation();
|
||||
Unit carrier = (Unit) getLocation();
|
||||
Location l = carrier.getLocation();
|
||||
|
||||
if (l instanceof Europe) {
|
||||
if (l instanceof Europe && carrier.getState() != TO_EUROPE && carrier.getState() != TO_AMERICA) {
|
||||
setLocation(l);
|
||||
setState(ACTIVE);
|
||||
} else if (getTile().getSettlement() != null) {
|
||||
setLocation(getTile());
|
||||
setState(ACTIVE);
|
||||
} else {
|
||||
throw new IllegalStateException("A unit may only leave a ship while in a harbour.");
|
||||
}
|
||||
|
@ -970,7 +1079,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* @param The amount of goods to buy.
|
||||
*/
|
||||
public void buyGoods(int type, int amount) {
|
||||
if (!isCarrier() || !(getLocation() instanceof Europe)) {
|
||||
if (!isCarrier() || !(getLocation() instanceof Europe && getState() != TO_EUROPE && getState() != TO_AMERICA)) {
|
||||
throw new IllegalStateException("Cannot buy goods when not a carrier or in Europe.");
|
||||
}
|
||||
|
||||
|
@ -978,7 +1087,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
goodsContainer.addGoods(type, amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets how many tools this unit is carrying.
|
||||
* @param numberOfTools The number to set it to.
|
||||
|
@ -992,10 +1101,10 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
if (isArmed()) {
|
||||
setArmed(false);
|
||||
}
|
||||
|
||||
|
||||
if (isMissionary()) {
|
||||
setMissionary(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int changeAmount = 0;
|
||||
|
@ -2573,6 +2682,8 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
unitElement.setAttribute("workLeft", Integer.toString(workLeft));
|
||||
unitElement.setAttribute("numberOfTools", Integer.toString(numberOfTools));
|
||||
unitElement.setAttribute("owner", owner.getID());
|
||||
unitElement.setAttribute("turnsOfTraining", Integer.toString(turnsOfTraining));
|
||||
unitElement.setAttribute("trainingType", Integer.toString(trainingType));
|
||||
|
||||
if (entryLocation != null) {
|
||||
unitElement.setAttribute("entryLocation", entryLocation.getID());
|
||||
|
@ -2622,7 +2733,9 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
workLeft = Integer.parseInt(unitElement.getAttribute("workLeft"));
|
||||
numberOfTools = Integer.parseInt(unitElement.getAttribute("numberOfTools"));
|
||||
owner = getGame().getPlayerByID(unitElement.getAttribute("owner"));
|
||||
|
||||
turnsOfTraining = Integer.parseInt(unitElement.getAttribute("turnsOfTraining"));
|
||||
trainingType = Integer.parseInt(unitElement.getAttribute("trainingType"));
|
||||
|
||||
if (owner == null) {
|
||||
logger.warning("VERY BAD: Can't find player with ID " + unitElement.getAttribute("owner") + "!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue