mirror of https://github.com/FreeCol/freecol.git
Fixed the problem of not beeing able to add a new 'FreeColGameObject' to the 'Game' when running the 'newTurn' methods.
This commit is contained in:
parent
e14b765d33
commit
9a0d6b7219
|
@ -39,7 +39,7 @@ public final class Messages {
|
|||
/**
|
||||
* Convenience method that finds the message with a particular id in the
|
||||
* default locale.
|
||||
*
|
||||
*
|
||||
* @param messageId the id of the message to find
|
||||
* @return the message with the specified id
|
||||
*/
|
||||
|
@ -83,15 +83,9 @@ public final class Messages {
|
|||
|
||||
/* this palaver is only necessary because Class.getPackage() can return
|
||||
* null */
|
||||
String packageName =
|
||||
getClass().getName().substring(
|
||||
0,
|
||||
getClass().getName().lastIndexOf('.'));
|
||||
String packageName = getClass().getName().substring(0, getClass().getName().lastIndexOf('.'));
|
||||
resources = (PropertyResourceBundle) ResourceBundle.getBundle(packageName + ".FreeColMessages", locale);
|
||||
|
||||
resources =
|
||||
(PropertyResourceBundle) ResourceBundle.getBundle(
|
||||
packageName + ".FreeColMessages",
|
||||
locale);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -343,14 +343,14 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
* Prepares this <code>Building</code> for a new turn.
|
||||
*/
|
||||
public void newTurn() {
|
||||
|
||||
|
||||
int goodsInput = 0;
|
||||
int goodsOutput = 0;
|
||||
int goodsInputType = -1;
|
||||
int goodsOutputType = -1;
|
||||
|
||||
|
||||
Goods thepackage;
|
||||
|
||||
|
||||
if (level == NOT_BUILT) return; // Don't do anything if the building does not exist.
|
||||
|
||||
// Figure out what's produced here and what it requires to do so.
|
||||
|
@ -402,13 +402,12 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
}
|
||||
}
|
||||
if (goodsOutput <= 0) return;
|
||||
|
||||
|
||||
// Actually produce the goods.
|
||||
colony.removeAmountAndTypeOfGoods(goodsInputType, goodsInput);
|
||||
thepackage = new Goods(getGame(), null, goodsOutputType, goodsOutput);
|
||||
thepackage.setLocation(colony);
|
||||
//colony.add(thepackage);
|
||||
getGame().mustRestartNewTurn = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -226,22 +226,24 @@ public class ColonyTile extends FreeColGameObject implements WorkLocation {
|
|||
* Prepares this <code>ColonyTile</code> for a new turn.
|
||||
*/
|
||||
public void newTurn() {
|
||||
if ((getUnit() == null) && !(isColonyCenterTile())) return; // Produce nothing if there's nobody to work the terrain.
|
||||
if (!(isColonyCenterTile())) {
|
||||
int amount = getUnit().getFarmedPotential(getUnit().getWorkType(), workTile);
|
||||
Goods g = new Goods(getGame(), null, getUnit().getWorkType(), amount);
|
||||
g.setLocation(colony);
|
||||
} else {
|
||||
int amount1 = workTile.potential(Goods.FOOD);
|
||||
Goods g = new Goods(getGame(), null, Goods.FOOD, amount1);
|
||||
g.setLocation(colony);
|
||||
int type2 = workTile.secondaryGoods();
|
||||
int amount2 = workTile.potential(type2);
|
||||
g = new Goods(getGame(), null, type2, amount2);
|
||||
g.setLocation(colony);
|
||||
}
|
||||
if ((getUnit() == null) && !(isColonyCenterTile())) {
|
||||
return; // Produce nothing if there's nobody to work the terrain.
|
||||
}
|
||||
|
||||
if (!(isColonyCenterTile())) {
|
||||
int amount = getUnit().getFarmedPotential(getUnit().getWorkType(), workTile);
|
||||
Goods g = new Goods(getGame(), null, getUnit().getWorkType(), amount);
|
||||
g.setLocation(colony);
|
||||
} else {
|
||||
int amount1 = workTile.potential(Goods.FOOD);
|
||||
Goods g = new Goods(getGame(), null, Goods.FOOD, amount1);
|
||||
g.setLocation(colony);
|
||||
int type2 = workTile.secondaryGoods();
|
||||
int amount2 = workTile.potential(type2);
|
||||
g = new Goods(getGame(), null, type2, amount2);
|
||||
g.setLocation(colony);
|
||||
}
|
||||
//colony.add(g);
|
||||
getGame().mustRestartNewTurn = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,9 +25,6 @@ abstract public class FreeColGameObject {
|
|||
private String id;
|
||||
private Game game;
|
||||
|
||||
//UGLY HACK to fix iterator issue involving goods, colonies, and new turns.
|
||||
public boolean hasDoneNewTurn;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -39,8 +36,6 @@ abstract public class FreeColGameObject {
|
|||
*/
|
||||
public FreeColGameObject(Game game) {
|
||||
this.game = game;
|
||||
|
||||
hasDoneNewTurn = false;
|
||||
|
||||
if (game != null) {
|
||||
//game.setFreeColGameObject(id, this);
|
||||
|
|
|
@ -48,7 +48,6 @@ public class Game extends FreeColGameObject {
|
|||
/* The market for Europe. */
|
||||
private Market market;
|
||||
|
||||
public boolean mustRestartNewTurn;
|
||||
|
||||
/**
|
||||
* Creates a new game model.
|
||||
|
@ -408,27 +407,12 @@ public class Game extends FreeColGameObject {
|
|||
* @see #setFreeColGameObject
|
||||
*/
|
||||
public void newTurn() {
|
||||
Iterator iterator = getFreeColGameObjectIterator();
|
||||
|
||||
mustRestartNewTurn = true;
|
||||
//Iterator iterator = getFreeColGameObjectIterator();
|
||||
Iterator iterator = ((HashMap) freeColGameObjects.clone()).values().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
FreeColGameObject freeColGameObject = (FreeColGameObject) iterator.next();
|
||||
freeColGameObject.hasDoneNewTurn = false;
|
||||
}
|
||||
|
||||
while (mustRestartNewTurn)
|
||||
{
|
||||
mustRestartNewTurn = false;
|
||||
iterator = getFreeColGameObjectIterator();
|
||||
while ((iterator.hasNext()) && (!mustRestartNewTurn)) {
|
||||
FreeColGameObject freeColGameObject = (FreeColGameObject) iterator.next();
|
||||
if (!freeColGameObject.hasDoneNewTurn)
|
||||
{
|
||||
freeColGameObject.hasDoneNewTurn = true;
|
||||
freeColGameObject.newTurn();
|
||||
}
|
||||
}
|
||||
freeColGameObject.newTurn();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -752,13 +752,19 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
public void setArmed(boolean b) {
|
||||
if ((b) && (!armed)) {
|
||||
if (getGoodsDumpLocation() != null) {
|
||||
if (getGoodsDumpLocation().getGoodsCount(Goods.MUSKETS) < 50) return;
|
||||
getGoodsDumpLocation().removeAmountAndTypeOfGoods(Goods.MUSKETS, 50);
|
||||
armed = true;
|
||||
if (getGoodsDumpLocation().getGoodsCount(Goods.MUSKETS) < 50) {
|
||||
return;
|
||||
}
|
||||
|
||||
getGoodsDumpLocation().removeAmountAndTypeOfGoods(Goods.MUSKETS, 50);
|
||||
armed = true;
|
||||
} else if (location instanceof Europe) {
|
||||
if (((getOwner().getGold()) / (getGame().getMarket().costToBuy(Goods.MUSKETS))) < 50) return;
|
||||
getGame().getMarket().buy(Goods.MUSKETS, 50, getOwner());
|
||||
armed = true;
|
||||
if (((getOwner().getGold()) / (getGame().getMarket().costToBuy(Goods.MUSKETS))) < 50) {
|
||||
return;
|
||||
}
|
||||
|
||||
getGame().getMarket().buy(Goods.MUSKETS, 50, getOwner());
|
||||
armed = true;
|
||||
} else {
|
||||
logger.warning("Attempting to arm a soldier outside of a colony or Europe!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue