|
| 1 | +package org.bk.ass; |
| 2 | + |
| 3 | +import bwapi.TechType; |
| 4 | +import bwapi.UnitType; |
| 5 | +import bwapi.UpgradeType; |
| 6 | + |
| 7 | +import static java.lang.Integer.max; |
| 8 | + |
| 9 | +/** Representing gas + minerals + supply */ |
| 10 | +public final class GMS { |
| 11 | + final int gas; |
| 12 | + final int minerals; |
| 13 | + final int supply; |
| 14 | + |
| 15 | + public GMS(int gas, int minerals, int supply) { |
| 16 | + this.gas = gas; |
| 17 | + this.minerals = minerals; |
| 18 | + this.supply = supply; |
| 19 | + } |
| 20 | + |
| 21 | + public static GMS unitCost(UnitType unitType) { |
| 22 | + return new GMS(unitType.gasPrice(), unitType.mineralPrice(), unitType.supplyRequired()); |
| 23 | + } |
| 24 | + |
| 25 | + public static GMS unitCost(org.openbw.bwapi4j.type.UnitType unitType) { |
| 26 | + return new GMS(unitType.gasPrice(), unitType.mineralPrice(), unitType.supplyRequired()); |
| 27 | + } |
| 28 | + |
| 29 | + public static GMS techCost(TechType techType) { |
| 30 | + return new GMS(techType.gasPrice(), techType.mineralPrice(), 0); |
| 31 | + } |
| 32 | + |
| 33 | + public static GMS techCost(org.openbw.bwapi4j.type.TechType techType) { |
| 34 | + return new GMS(techType.gasPrice(), techType.mineralPrice(), 0); |
| 35 | + } |
| 36 | + |
| 37 | + public static GMS researchCost(UpgradeType upgradeType, int level) { |
| 38 | + return new GMS(upgradeType.gasPrice(level), upgradeType.mineralPrice(level), 0); |
| 39 | + } |
| 40 | + |
| 41 | + public static GMS researchCost(org.openbw.bwapi4j.type.UpgradeType upgradeType, int level) { |
| 42 | + return new GMS(upgradeType.gasPrice(level), upgradeType.mineralPrice(level), 0); |
| 43 | + } |
| 44 | + |
| 45 | + public GMS subtract(GMS gms) { |
| 46 | + return new GMS(gas - gms.gas, minerals - gms.minerals, supply - gms.supply); |
| 47 | + } |
| 48 | + |
| 49 | + public GMS add(GMS gms) { |
| 50 | + return new GMS(gas + gms.gas, minerals + gms.minerals, supply + gms.supply); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * If all components (gas, minerals, supply) of this value are non-negative, returns true if all |
| 55 | + * are >= that of the given value. If a component is negative, returns false if the given |
| 56 | + * value's component is >= 0. <br> |
| 57 | + * Usually all components are >= 0 and this can be used to check if a price could be payed |
| 58 | + * <em>now</em>. <br> |
| 59 | + * If planning ahead is used, components could already be negative. But if the cost (ie. supply) |
| 60 | + * is 0, it might still be possible to purchase it immediately. |
| 61 | + */ |
| 62 | + public boolean greaterOrEqual(GMS gms) { |
| 63 | + return max(0, gas) >= gms.gas |
| 64 | + && max(0, minerals) >= gms.minerals |
| 65 | + && max(0, supply) >= gms.supply; |
| 66 | + } |
| 67 | +} |
0 commit comments