diff --git a/core/src/com/etheller/warsmash/TestMain.java b/core/src/com/etheller/warsmash/TestMain.java deleted file mode 100644 index bc30512..0000000 --- a/core/src/com/etheller/warsmash/TestMain.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.etheller.warsmash; - -import com.etheller.warsmash.util.War3ID; - -public class TestMain { - public static void main(final String[] args) { - if (true) { - System.out.println(War3ID.fromString("hwat").getValue()); - System.out.println(Integer.toHexString(War3ID.fromString("hwat").getValue())); - System.out.println(new War3ID(0x68776174)); - return; - } -// System.out.println(Integer.parseInt("4294967295")); - for (int i = 1; i <= 30; i++) { -// System.out.println(a(i)); - } - - int checkX = 0; - int checkY = 0; - for (int i = 0; i < 300; i++) { - System.out.println(checkX + "," + checkY); - final double angle = ((((int) Math.floor(Math.sqrt((4 * i) + 1))) % 4) * Math.PI) / 2; - checkX += (int) Math.sin(angle); - checkY += (int) Math.cos(angle); - } - } - - public static int a(final int n) { - if (n == 1) { - return 0; - } - else { - return a(n - 1) - (int) Math.sin(((Math.floor(Math.sqrt((4 * (n - 2)) + 1)) % 4) * Math.PI) / 2); - } - } -} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardPopulatingAbilityVisitor.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardPopulatingAbilityVisitor.java index fd181d2..f98057f 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardPopulatingAbilityVisitor.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardPopulatingAbilityVisitor.java @@ -117,7 +117,8 @@ public class CommandCardPopulatingAbilityVisitor implements CAbilityVisitor targetsAllowed; private CBehaviorCoupleInstant behaviorCoupleInstant; + private final int goldCost; + private final int lumberCost; public CAbilityCoupleInstant(final int handleId, final War3ID alias, final War3ID resultingUnitType, final War3ID partnerUnitType, final boolean moveToPartner, final float castRange, final float area, - final EnumSet targetsAllowed) { + final EnumSet targetsAllowed, final int goldCost, final int lumberCost) { super(handleId, alias); this.resultingUnitType = resultingUnitType; this.partnerUnitType = partnerUnitType; @@ -39,6 +43,8 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv this.castRange = castRange; this.area = area; this.targetsAllowed = targetsAllowed; + this.goldCost = goldCost; + this.lumberCost = lumberCost; } @Override @@ -123,7 +129,18 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv @Override protected void innerCheckCanUse(final CSimulation game, final CUnit unit, final int orderId, final AbilityActivationReceiver receiver) { - receiver.useOk(); + final CPlayer player = game.getPlayer(unit.getPlayerIndex()); + if (player.getGold() >= this.goldCost) { + if (player.getLumber() >= this.lumberCost) { + receiver.useOk(); + } + else { + receiver.notEnoughResources(ResourceType.LUMBER); + } + } + else { + receiver.notEnoughResources(ResourceType.GOLD); + } } public float getCastRange() { @@ -142,6 +159,14 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv return this.resultingUnitType; } + public int getGoldCost() { + return this.goldCost; + } + + public int getLumberCost() { + return this.lumberCost; + } + private final class PossiblePairFinderEnum implements CUnitEnumFunction { private final CUnit unit; private CUnit pairMatchFound = null; @@ -176,4 +201,13 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv } } + @Override + public int getUIGoldCost() { + return this.goldCost; + } + + @Override + public int getUILumberCost() { + return this.lumberCost; + } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/definitions/impl/CAbilityTypeDefinitionCoupleInstant.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/definitions/impl/CAbilityTypeDefinitionCoupleInstant.java index 9d6d73c..244ef6a 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/definitions/impl/CAbilityTypeDefinitionCoupleInstant.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/definitions/impl/CAbilityTypeDefinitionCoupleInstant.java @@ -36,7 +36,7 @@ public class CAbilityTypeDefinitionCoupleInstant final EnumSet targetsAllowedAtLevel = CTargetType.parseTargetTypeSet(targetsAllowedAtLevelString); return new CAbilityTypeCoupleInstantLevelData(targetsAllowedAtLevel, resultingUnitTypeId, partnerUnitTypeId, - moveToPartner, castRange, area); + moveToPartner, castRange, area, goldCost, lumberCost); } @Override diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/impl/CAbilityTypeCoupleInstant.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/impl/CAbilityTypeCoupleInstant.java index 8e70ed6..b3a5016 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/impl/CAbilityTypeCoupleInstant.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilities/types/impl/CAbilityTypeCoupleInstant.java @@ -19,7 +19,7 @@ public class CAbilityTypeCoupleInstant extends CAbilityType targetsAllowed, final War3ID resultingUnitTypeId, final War3ID partnerUnitTypeId, final boolean moveToPartner, - final float castRange, final float area) { + final float castRange, final float area, final int goldCost, final int lumberCost) { super(targetsAllowed); this.resultingUnitTypeId = resultingUnitTypeId; this.partnerUnitTypeId = partnerUnitTypeId; this.moveToPartner = moveToPartner; this.castRange = castRange; this.area = area; + this.goldCost = goldCost; + this.lumberCost = lumberCost; } public War3ID getResultingUnitTypeId() { @@ -44,4 +48,12 @@ public class CAbilityTypeCoupleInstantLevelData extends CAbilityTypeLevelData { return this.area; } + public int getGoldCost() { + return this.goldCost; + } + + public int getLumberCost() { + return this.lumberCost; + } + } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/test/CBehaviorCoupleInstant.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/test/CBehaviorCoupleInstant.java index f923351..9930f37 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/test/CBehaviorCoupleInstant.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/behaviors/test/CBehaviorCoupleInstant.java @@ -54,13 +54,18 @@ public class CBehaviorCoupleInstant extends CAbstractRangedBehavior { if (targetBehavior instanceof CBehaviorCoupleInstant) { if (((CBehaviorCoupleInstant) targetBehavior).isWithinRange(simulation)) { // we are both within range - final CUnit newUnit = simulation.createUnit(this.abilityCoupleInstant.getResultingUnitType(), - this.unit.getPlayerIndex(), this.unit.getX(), this.unit.getY(), this.unit.getFacing()); - simulation.unitPreferredSelectionReplacement(this.unit, newUnit); - simulation.unitPreferredSelectionReplacement(((CUnit) this.target), newUnit); - simulation.removeUnit(this.unit); - simulation.removeUnit((CUnit) this.target); - simulation.unitSoundEffectEvent(newUnit, this.abilityCoupleInstant.getAlias()); + final int goldCost = this.abilityCoupleInstant.getGoldCost(); + final int lumberCost = this.abilityCoupleInstant.getLumberCost(); + if (((goldCost == 0) && (lumberCost == 0)) + || simulation.getPlayer(this.unit.getPlayerIndex()).charge(goldCost, lumberCost)) { + final CUnit newUnit = simulation.createUnit(this.abilityCoupleInstant.getResultingUnitType(), + this.unit.getPlayerIndex(), this.unit.getX(), this.unit.getY(), this.unit.getFacing()); + simulation.unitPreferredSelectionReplacement(this.unit, newUnit); + simulation.unitPreferredSelectionReplacement(((CUnit) this.target), newUnit); + simulation.removeUnit(this.unit); + simulation.removeUnit((CUnit) this.target); + simulation.unitSoundEffectEvent(newUnit, this.abilityCoupleInstant.getAlias()); + } return this.unit.pollNextOrderBehavior(simulation); } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java index 2cb879d..c8686c9 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java @@ -49,7 +49,7 @@ public class CAbilityData { if (mutableGameObject == null) { return null; } - final War3ID code = mutableGameObject.getCode(); + final War3ID code = War3ID.fromString(mutableGameObject.readSLKTag("code")); final CAbilityTypeDefinition abilityTypeDefinition = this.codeToAbilityTypeDefinition.get(code); if (abilityTypeDefinition != null) { abilityType = abilityTypeDefinition.createAbilityType(alias, mutableGameObject); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/players/CPlayer.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/players/CPlayer.java index 956a396..106772b 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/players/CPlayer.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/players/CPlayer.java @@ -121,6 +121,17 @@ public class CPlayer extends CBasePlayer { this.stateNotifier.goldChanged(); } + public boolean charge(final int gold, final int lumber) { + if ((this.lumber >= lumber) && (this.gold >= gold)) { + this.lumber -= lumber; + this.gold -= gold; + this.stateNotifier.lumberChanged(); + this.stateNotifier.goldChanged(); + return true; + } + return false; + } + public void refundFor(final CUnitType unitType) { this.lumber += unitType.getLumberCost(); this.gold += unitType.getGoldCost();