Rework colony bonus handling.

This commit is contained in:
Mike Pope 2016-08-04 13:13:12 +09:30
parent 62879eedc0
commit 2a11f361ff
10 changed files with 63 additions and 18 deletions

View File

@ -20,7 +20,7 @@
In case of incompatible changes, please update version number and
XSD schema for validation.
-->
<freecol-specification id="classic" version="0.111">
<freecol-specification id="classic" version="0.112">
<!-- Modifiers that are not attached to other game object
types. They may be modified, but MUST NOT be removed. -->
@ -2433,7 +2433,7 @@
<building-type id="model.building.ironWorks"
extends="model.building.blacksmithShop"
upgrades-from="model.building.blacksmithShop"
experts-with-connections-production="4"
experts-with-connections-production="4" rebel-factor="1.5"
required-population="8" upkeep="15">
<production>
<input goods-type="model.goods.ore" value="6"/>
@ -2469,7 +2469,7 @@
<building-type id="model.building.cigarFactory"
extends="model.building.tobacconistShop"
upgrades-from="model.building.tobacconistShop"
experts-with-connections-production="4"
experts-with-connections-production="4" rebel-factor="1.5"
required-population="8" upkeep="15">
<production>
<input goods-type="model.goods.tobacco" value="6"/>
@ -2505,7 +2505,7 @@
<building-type id="model.building.textileMill"
extends="model.building.weaverShop"
upgrades-from="model.building.weaverShop"
experts-with-connections-production="4"
experts-with-connections-production="4" rebel-factor="1.5"
required-population="8" upkeep="15">
<production>
<input goods-type="model.goods.cotton" value="6"/>
@ -2541,7 +2541,7 @@
<building-type id="model.building.rumFactory"
extends="model.building.rumDistillery"
upgrades-from="model.building.rumDistillery"
experts-with-connections-production="4"
experts-with-connections-production="4" rebel-factor="1.5"
required-population="8" upkeep="15">
<production>
<input goods-type="model.goods.sugar" value="6"/>
@ -2577,7 +2577,7 @@
<building-type id="model.building.furFactory"
extends="model.building.furTradingPost"
upgrades-from="model.building.furTradingPost"
experts-with-connections-production="4"
experts-with-connections-production="4" rebel-factor="1.5"
required-population="6" upkeep="15">
<production>
<input goods-type="model.goods.furs" value="6"/>

View File

@ -20,7 +20,7 @@
In case of incompatible changes, please update version number and
XSD schema for validation.
-->
<freecol-specification id="freecol" version="0.111" extends="classic">
<freecol-specification id="freecol" version="0.112" extends="classic">
<goods-types>
<goods-type id="model.goods.horses" is-farmed="false"

View File

@ -54,6 +54,7 @@
<xs:attribute name="maximum-skill" type="xs:int"/>
<xs:attribute name="minimum-skill" type="xs:int"/>
<xs:attribute name="priority" type="xs:nonNegativeInteger"/>
<xs:attribute name="rebel-factor" type="xs:float"/>
<xs:attribute name="required-population" type="xs:nonNegativeInteger"/>
<xs:attribute name="upgrades-from" type="BuildingTypeId"/>
<xs:attribute name="upkeep" type="xs:int"/>

View File

@ -20,7 +20,7 @@
You should have received a copy of the GNU General Public License
along with FreeCol. If not, see http://www.gnu.org/licenses
XSD for specification version 0.111
XSD for specification version 0.112
CHANGELOG:
0.26: add capture-equipment
0.27: add limits
@ -109,6 +109,7 @@
0.109: Big reorganization.
0.110: Add experts-with-connections-production attribute to BuildingType.
0.111: Add unit-change-types etc.
0.112: Added rebel-factor attribute to building-type.
</xs:documentation>
</xs:annotation>

View File

@ -528,7 +528,7 @@ public class Building extends WorkLocation
owner.getModifiers(id, type, turn))
// With a unit, also the unit specific bonuses
: concat(this.getModifiers(id, unitType, turn),
colony.getProductionModifiers(goodsType),
colony.getProductionModifiers(goodsType, unitType, this),
unitType.getModifiers(id, type, turn),
owner.getModifiers(id, unitType, turn));
}
@ -542,6 +542,14 @@ public class Building extends WorkLocation
: getType().getAvailableProductionTypes(unattended);
}
/**
* {@inheritDoc}
*/
@Override
public float getRebelFactor() {
return getType().getRebelFactor();
}
// Interface Consumer

View File

@ -58,6 +58,9 @@ public final class BuildingType extends BuildableType {
/** Maximum production from the "experts have connections" option. */
private int expertConnectionProduction = 0;
/** The multiplier for the colony rebel bonus for this building type. */
private float rebelFactor = 1.0f;
/** The building type this upgrades from. */
private BuildingType upgradesFrom = null;
@ -117,6 +120,16 @@ public final class BuildingType extends BuildableType {
return this.expertConnectionProduction;
}
/**
* Get a work location specific factor to multiply the colony
* rebel bonus by.
*
* @return The rebel factor.
*/
public float getRebelFactor() {
return this.rebelFactor;
}
/**
* The consumption priority of a Building of this type. The higher
* the priority, the earlier will the Consumer be allowed to
@ -359,6 +372,7 @@ public final class BuildingType extends BuildableType {
private static final String MINIMUM_SKILL_TAG = "minimum-skill";
private static final String PRIORITY_TAG = "priority";
private static final String PRODUCTION_TAG = "production";
private static final String REBEL_FACTOR_TAG = "rebel-factor";
private static final String UPGRADES_FROM_TAG = "upgrades-from";
private static final String UPKEEP_TAG = "upkeep";
private static final String WORKPLACES_TAG = "workplaces";
@ -405,6 +419,8 @@ public final class BuildingType extends BuildableType {
xw.writeAttribute(EXPERTS_WITH_CONNECTION_PRODUCTION_TAG,
this.expertConnectionProduction);
xw.writeAttribute(REBEL_FACTOR_TAG, this.rebelFactor);
}
/**
@ -471,6 +487,9 @@ public final class BuildingType extends BuildableType {
= xr.getAttribute(EXPERTS_WITH_CONNECTION_PRODUCTION_TAG,
parent.expertConnectionProduction);
this.rebelFactor = xr.getAttribute(REBEL_FACTOR_TAG,
parent.rebelFactor);
// @compat 0.10.6
int basicProduction = xr.getAttribute(BASIC_PRODUCTION_TAG, -1);
if (basicProduction > 0) {

View File

@ -1954,15 +1954,15 @@ public class Colony extends Settlement implements Nameable, TradeLocation {
* generated from the current production bonus.
*
* @param goodsType The <code>GoodsType</code> to produce.
* @param unitType An optional <code>UnitType</code> to do the work.
* @param workLocation The <code>WorkLocation</code> where the work
* is done.
* @return A stream of suitable <code>Modifier</code>s.
*/
public Stream<Modifier> getProductionModifiers(GoodsType goodsType) {
public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
UnitType unitType, WorkLocation wl) {
if (productionBonus == 0) return Stream.<Modifier>empty();
int bonus = productionBonus;
if (max(getWorkLocationsForProducing(goodsType),
WorkLocation::getLevel) == FACTORY_LEVEL) {
bonus = (int)Math.floor(1.5 * bonus);
}
int bonus = (int)Math.floor(productionBonus * wl.getRebelFactor());
Modifier mod = new Modifier(goodsType.getId(), bonus,
Modifier.ModifierType.ADDITIVE,
Specification.SOL_MODIFIER_SOURCE);

View File

@ -454,14 +454,14 @@ public class ColonyTile extends WorkLocation {
return (unitType != null)
// Unit modifiers apply
? concat(workTile.getProductionModifiers(goodsType, unitType),
colony.getProductionModifiers(goodsType),
colony.getProductionModifiers(goodsType, unitType, this),
unitType.getModifiers(id, type, turn),
((owner == null) ? null
: owner.getModifiers(id, unitType, turn)))
: (isColonyCenterTile())
// Unattended only possible in center, colony modifiers apply
? concat(workTile.getProductionModifiers(goodsType, null),
colony.getProductionModifiers(goodsType),
colony.getProductionModifiers(goodsType, null, this),
colony.getModifiers(id, null, turn),
((owner == null) ? null
: owner.getModifiers(id, type, turn)))
@ -480,6 +480,14 @@ public class ColonyTile extends WorkLocation {
: workTile.getType().getAvailableProductionTypes(unattended);
}
/**
* {@inheritDoc}
*/
@Override
public float getRebelFactor() {
return 1.0f;
}
/**
* {@inheritDoc}
*/

View File

@ -869,6 +869,14 @@ public abstract class WorkLocation extends UnitLocation
*/
public abstract List<ProductionType> getAvailableProductionTypes(boolean unattended);
/**
* Get a work location specific factor to multiply the colony
* rebel bonus by.
*
* @return The rebel factor.
*/
public abstract float getRebelFactor();
/**
* Evaluate this work location for a given player.
* To be overridden by subclasses.

View File

@ -1013,7 +1013,7 @@ public class BuildingTest extends FreeColTestCase {
{ 2, 2, 4, 6, 12 }, // 0
{ 3, 3, 5, 7, 14 }, // 1
{ 4, 4, 6, 8, 16 }, // 2
}, { // iron works
}, { // factory
{ 0, 0, 3, 6, 12 }, // -2
{ 1, 1, 4, 7, 14 }, // -1
{ 3, 3, 6, 9, 18 }, // 0