From: <mp...@us...> - 2012-05-25 10:40:33
|
Revision: 9855 http://freecol.svn.sourceforge.net/freecol/?rev=9855&view=rev Author: mpope Date: 2012-05-25 10:40:19 +0000 (Fri, 25 May 2012) Log Message: ----------- Native units go home for equipment, BR#3487691. Modified Paths: -------------- freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java freecol/trunk/src/net/sf/freecol/common/model/Unit.java freecol/trunk/src/net/sf/freecol/server/ai/NativeAIPlayer.java freecol/trunk/test/src/net/sf/freecol/common/model/IndianSettlementTest.java Modified: freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java =================================================================== --- freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java 2012-05-25 10:37:08 UTC (rev 9854) +++ freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java 2012-05-25 10:40:19 UTC (rev 9855) @@ -910,12 +910,12 @@ /** * Allows spread of horses and arms between settlements - * @param settlement + * + * @param settlement The other <code>IndianSettlement</code> to trade with. */ - public void tradeGoodsWithSetlement(IndianSettlement settlement) { + public void tradeGoodsWithSettlement(IndianSettlement settlement) { GoodsType armsType = getSpecification().getGoodsType("model.goods.muskets"); GoodsType horsesType = getSpecification().getGoodsType("model.goods.horses"); - List<GoodsType> goodsToTrade = new ArrayList<GoodsType>(); goodsToTrade.add(armsType); goodsToTrade.add(horsesType); Modified: freecol/trunk/src/net/sf/freecol/common/model/Unit.java =================================================================== --- freecol/trunk/src/net/sf/freecol/common/model/Unit.java 2012-05-25 10:37:08 UTC (rev 9854) +++ freecol/trunk/src/net/sf/freecol/common/model/Unit.java 2012-05-25 10:40:19 UTC (rev 9855) @@ -2740,20 +2740,22 @@ } } - - // TODO: make these go away, if possible, private if not + /** + * Does the unit have arms? + * + * @return True if the unit has arms. + */ public boolean isArmed() { - if(getOwner().isIndian()){ - return equipment.containsKey(getSpecification().getEquipmentType("model.equipment.indian.muskets")); - } - return equipment.containsKey(getSpecification().getEquipmentType("model.equipment.muskets")); + return getRole() == Role.SOLDIER || getRole() == Role.DRAGOON; } + /** + * Does the unit have a mount? + * + * @return True if the unit have a mount. + */ public boolean isMounted() { - if(getOwner().isIndian()){ - return equipment.containsKey(getSpecification().getEquipmentType("model.equipment.indian.horses")); - } - return equipment.containsKey(getSpecification().getEquipmentType("model.equipment.horses")); + return getRole() == Role.SCOUT || getRole() == Role.DRAGOON; } /** Modified: freecol/trunk/src/net/sf/freecol/server/ai/NativeAIPlayer.java =================================================================== --- freecol/trunk/src/net/sf/freecol/server/ai/NativeAIPlayer.java 2012-05-25 10:37:08 UTC (rev 9854) +++ freecol/trunk/src/net/sf/freecol/server/ai/NativeAIPlayer.java 2012-05-25 10:40:19 UTC (rev 9855) @@ -185,7 +185,7 @@ getAIRandom(), settlements.size()); IndianSettlement settlement = settlements.get(n); if (settlement != is) { - is.tradeGoodsWithSetlement(settlement); + is.tradeGoodsWithSettlement(settlement); } } for (IndianSettlement is : settlements) { @@ -203,6 +203,7 @@ public void equipBraves(IndianSettlement is) { final Specification spec = getSpecification(); List<Unit> units = is.getUnitList(); + units.addAll(is.getTile().getUnitList()); roles: for (Role r : new Role[] { Role.DRAGOON, Role.SOLDIER, Role.SCOUT }) { List<EquipmentType> e = r.getRoleEquipment(spec); @@ -372,7 +373,12 @@ * Gives a mission to all units. */ private void giveNormalMissions() { - AIMain aiMain = getAIMain(); + final AIMain aiMain = getAIMain(); + final Specification spec = aiMain.getGame().getSpecification(); + final List<EquipmentType> scoutEq + = Unit.Role.SCOUT.getRoleEquipment(spec); + final List<EquipmentType> soldierEq + = Unit.Role.SOLDIER.getRoleEquipment(spec); for (AIUnit aiUnit : getAIUnits()) { final Unit unit = aiUnit.getUnit(); @@ -389,6 +395,7 @@ // Check the current mission, and assign a new one to m if needed. Settlement settlement = unit.getSettlement(); + IndianSettlement is; Mission m = aiUnit.getMission(); if (m != null && m.isValid() && !m.isOneTime()) { m = null; @@ -396,6 +403,12 @@ + unit.getTile().getUnitCount() <= 1)) { m = new DefendSettlementMission(aiMain, aiUnit, settlement); + } else if ((is = unit.getIndianSettlement()) != null + && ((!unit.isMounted() && is.canProvideEquipment(scoutEq)) + || (!unit.isArmed() && is.canProvideEquipment(soldierEq)))) { + // Go home for new equipment if the home settlement has them. + m = new DefendSettlementMission(aiMain, aiUnit, is); + } else if (UnitWanderHostileMission.invalidReason(aiUnit) == null) { if (m instanceof UnitWanderHostileMission) { m = null; Modified: freecol/trunk/test/src/net/sf/freecol/common/model/IndianSettlementTest.java =================================================================== --- freecol/trunk/test/src/net/sf/freecol/common/model/IndianSettlementTest.java 2012-05-25 10:37:08 UTC (rev 9854) +++ freecol/trunk/test/src/net/sf/freecol/common/model/IndianSettlementTest.java 2012-05-25 10:40:19 UTC (rev 9855) @@ -86,7 +86,7 @@ assertEquals(wrongQtyMusketsMsg,none,camp2.getGoodsCount(musketsType)); assertEquals(wrongQtyHorsesMsg,none,camp2.getGoodsCount(horsesType)); - camp1.tradeGoodsWithSetlement(camp2); + camp1.tradeGoodsWithSettlement(camp2); assertEquals(wrongQtyMusketsMsg,enoughToShare / 2,camp1.getGoodsCount(musketsType)); assertEquals(wrongQtyHorsesMsg,notEnoughToShare,camp1.getGoodsCount(horsesType)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |