|
From: Michael B. <Mic...@gm...> - 2009-06-03 15:12:14
|
ata...@us... wrote: > Revision: 5468 > http://freecol.svn.sourceforge.net/freecol/?rev=5468&view=rev > Author: atamanio > Date: 2009-06-02 16:34:15 +0000 (Tue, 02 Jun 2009) > > Log Message: > ----------- > Fix for estimating odds against opponent colony without visibility (client side only) > > Modified Paths: > -------------- > freecol/trunk/src/net/sf/freecol/common/model/Colony.java > freecol/trunk/src/net/sf/freecol/common/model/Tile.java > > Modified: freecol/trunk/src/net/sf/freecol/common/model/Colony.java > =================================================================== > --- freecol/trunk/src/net/sf/freecol/common/model/Colony.java 2009-06-02 15:05:30 UTC (rev 5467) > +++ freecol/trunk/src/net/sf/freecol/common/model/Colony.java 2009-06-02 16:34:15 UTC (rev 5468) > @@ -761,15 +761,23 @@ > * > * @param attacker The unit that would be attacking this colony. > * @return The <code>Unit</code> that has been chosen to defend this > - * colony. > + * colony, or <code>null</code> if the colony belongs to another > + * player and client is not permitted to view contents. > * @see Tile#getDefendingUnit(Unit) > * @throws IllegalStateException if there are units in the colony > */ > @Override > public Unit getDefendingUnit(Unit attacker) { > + List<Unit> unitList = getUnitList(); > + > + if (unitCount != -1 && unitList.isEmpty()) { > + // There are units, but we don't see them > + return null; > + } > + > Unit defender = null; > float defencePower = -1.0f; > - for (Unit nextUnit : getUnitList()) { > + for (Unit nextUnit : unitList) { > float tmpPower = getGame().getCombatModel().getDefencePower(attacker, nextUnit); > if (tmpPower > defencePower || defender == null) { > defender = nextUnit; > > Modified: freecol/trunk/src/net/sf/freecol/common/model/Tile.java > =================================================================== > --- freecol/trunk/src/net/sf/freecol/common/model/Tile.java 2009-06-02 15:05:30 UTC (rev 5467) > +++ freecol/trunk/src/net/sf/freecol/common/model/Tile.java 2009-06-02 16:34:15 UTC (rev 5468) > @@ -385,7 +385,7 @@ > // on land tiles, ships are docked in port and cannot defend > // on ocean tiles, land units behave as ship cargo and cannot defend > float tmpPower = getGame().getCombatModel().getDefencePower(attacker,nextUnit); > - if (tmpPower > defencePower) { > + if (tmpPower > defencePower || tileDefender == null) { > tileDefender = nextUnit; > defencePower = tmpPower; > } > > > It would be great if you could port straight-forward fixes like this to the 0.8.x branch, too. As a rule of thumb, if the patch applies cleanly to 0.8.x, commit. If not, don't bother. Regards Michael |