Skip to content

Commit d83a1ab

Browse files
author
Bytekeeper
committed
Added plague damage support
1 parent dca2870 commit d83a1ab

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

src/main/java/org/bk/ass/Agent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class Agent {
4646
int stopFrames;
4747
int remainingStimFrames;
4848
boolean canStim;
49+
int plagueDamagePerFrameShifted;
4950

5051
// Is Zerg and not an Egg/Larva
5152
boolean regeneratesHealth;
@@ -337,6 +338,11 @@ public Agent setHpConstructionRate(int buildTime) {
337338
return this;
338339
}
339340

341+
public Agent setPlagueDamage(int plagueDamage) {
342+
this.plagueDamagePerFrameShifted = (plagueDamage << 8) / 76;
343+
return this;
344+
}
345+
340346
public enum TargetingPriority {
341347
LOW,
342348
MEDIUM,

src/main/java/org/bk/ass/BWAPI4JAgentFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public Agent of(PlayerUnit unit) {
230230
hasEnergyUpgrade(unitType, player));
231231
if (map != null && !unit.isFlying()) {
232232
agent.setElevationLevel(map.getGroundHeight(unit.getTilePosition()));
233-
// agent.setProtectedByDarkSwarm(unit.isUnderDarkSwarm()); Not supported by BWAPI4J currently
234233
}
235234
if (unitType == UnitType.Terran_Marine || unitType == UnitType.Terran_Firebat) {
236235
agent.setCanStim(player.hasResearched(TechType.Stim_Packs));

src/main/java/org/bk/ass/BWMirrorAgentFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ public Agent of(
209209
.setUserObject(unit)
210210
.setBurrowed(unit.isBurrowed())
211211
.setStasised(unit.isStasised())
212-
.setLockeddown(unit.isLockedDown());
212+
.setLockeddown(unit.isLockedDown())
213+
.setPlagueDamage(unit.isPlagued() ? WeaponType.Plague.damageAmount() : 0);
213214
}
214215

215216
public Agent of(Unit unit) {

src/main/java/org/bk/ass/Simulator.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ private void updateStats(UnorderedCollection<Agent> agents) {
199199
if (agent.cooldown > 0) {
200200
agent.cooldown--;
201201
}
202+
if (agent.shieldsShifted < agent.maxShieldsShifted) {
203+
agent.shieldsShifted += 7;
204+
if (agent.shieldsShifted > agent.maxShieldsShifted) {
205+
agent.shieldsShifted = agent.maxShieldsShifted;
206+
}
207+
}
208+
if (agent.plagueDamagePerFrameShifted < agent.healthShifted) {
209+
agent.healthShifted -= agent.plagueDamagePerFrameShifted;
210+
}
202211
if (agent.remainingStimFrames > 0) {
203212
agent.remainingStimFrames--;
204213
}
@@ -208,12 +217,6 @@ private void updateStats(UnorderedCollection<Agent> agents) {
208217
agent.healthShifted = agent.maxHealthShifted;
209218
}
210219
}
211-
if (agent.shieldsShifted < agent.maxShieldsShifted) {
212-
agent.shieldsShifted += 7;
213-
if (agent.shieldsShifted > agent.maxShieldsShifted) {
214-
agent.shieldsShifted = agent.maxShieldsShifted;
215-
}
216-
}
217220
agent.energyShifted += 8;
218221
if (agent.energyShifted > agent.maxEnergyShifted) {
219222
agent.energyShifted = agent.maxEnergyShifted;

src/test/java/org/bk/ass/SimulatorTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.junit.jupiter.api.Test;
66
import org.openbw.bwapi4j.test.BWDataProvider;
77
import org.openbw.bwapi4j.type.UnitType;
8+
import org.openbw.bwapi4j.type.WeaponType;
89

910
import static org.assertj.core.api.Assertions.assertThat;
1011
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -771,4 +772,45 @@ void darkSwarmZerglingVsMarines() {
771772
assertThat(simulator.getAgentsA()).isEmpty();
772773
assertThat(simulator.getAgentsB()).isNotEmpty();
773774
}
775+
776+
@Test
777+
void shouldDealPlagueDamage() {
778+
// GIVEN
779+
simulator.addAgentA(
780+
factory.of(UnitType.Terran_Marine).setPlagueDamage(WeaponType.Plague.damageAmount()));
781+
782+
// Dummy unit
783+
simulator.addAgentB(factory.of(UnitType.Protoss_Carrier));
784+
785+
// WHEN
786+
simulator.simulate(1);
787+
788+
// THEN
789+
assertThat(simulator.getAgentsA())
790+
.first()
791+
.extracting(a -> a.healthShifted)
792+
.isEqualTo(9230); // ~4 damage taken
793+
}
794+
795+
@Test
796+
void shouldNotDieFromPlague() {
797+
// GIVEN
798+
simulator.addAgentA(
799+
factory
800+
.of(UnitType.Terran_Marine)
801+
.setPlagueDamage(WeaponType.Plague.damageAmount())
802+
.setHealth(2));
803+
804+
// Dummy unit
805+
simulator.addAgentB(factory.of(UnitType.Protoss_Carrier));
806+
807+
// WHEN
808+
simulator.simulate(1);
809+
810+
// THEN
811+
assertThat(simulator.getAgentsA())
812+
.first()
813+
.extracting(a -> a.healthShifted)
814+
.isEqualTo(512); // No damage taken
815+
}
774816
}

0 commit comments

Comments
 (0)