Skip to content

Commit

Permalink
#36 Prepared more generic approach for handling "not-so-stable" ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocraft committed Jul 29, 2020
1 parent c582759 commit 482156d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,6 +31,7 @@
import com.github.ocraft.s2client.bot.ClientError;
import com.github.ocraft.s2client.bot.gateway.ProtoInterface;
import com.github.ocraft.s2client.protocol.BuilderSyntax;
import com.github.ocraft.s2client.protocol.data.Units;
import com.github.ocraft.s2client.protocol.game.GameStatus;
import com.github.ocraft.s2client.protocol.request.Request;
import com.github.ocraft.s2client.protocol.request.Requests;
Expand Down Expand Up @@ -109,6 +110,7 @@ private boolean connect(
.ifPresentOrElse(ping -> {
this.dataVersion = ping.getDataVersion();
this.baseBuild = ping.getBaseBuild();
Units.remapForBuild(this.baseBuild);
}, () -> {
throw new IllegalStateException("ping failed");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public final class Versions {

public static final String API_VERSION = "4.12.0.80188";
public static final String API_VERSION = "5.0.0.81009";

private static final Map<Integer, GameVersion> gameVersions = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ public enum Abilities implements Ability {
BATTLECRUISER_STOP_CHEER(3785, NONE),
BATTLECRUISER_STOP_DANCE(3786, NONE),
VIPER_PARASITIC_BOMB_RELAY_PARASITIC_BOMB(3789, NONE),
PARASITIC_BOMB_RELAY_DODGE_PARASITIC_BOMB(3791, NONE);
PARASITIC_BOMB_RELAY_DODGE_PARASITIC_BOMB(3791, NONE),
BATTERY_OVERCHARGE(4107, NONE),
AMORPHOUS_ARMOR_CLOUD(4109, NONE);

public static final class Other implements Ability {

Expand Down Expand Up @@ -610,7 +612,7 @@ public String toString() {
EnumSet.allOf(Abilities.class).forEach(ability -> abilityIdMap.put(ability.getAbilityId(), ability));
}

private final int abilityId;
private int abilityId;
private final EnumSet<Target> targets;

Abilities(int abilityId, Target... targets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -323,8 +323,9 @@ public enum Buffs implements Buff {
NEXUS_SHIELD_OVERCHARGE(286),
PARASITIC_BOMB_DELAY_TIMED_LIFE(287),
TRANSFUSION(288),
INHIBITOR_ZONE_TEMPORAL_FIELD(289);

INHIBITOR_ZONE_TEMPORAL_FIELD(289),
BATTERY_OVERCHARGE(297),
AMORPHOUS_ARMOR_CLOUD(295);

public static final class Other implements Buff {

Expand Down Expand Up @@ -354,7 +355,7 @@ public String toString() {
}
}

private static Map<Integer, Buff> buffIdMap = new HashMap<>();
private static final Map<Integer, Buff> buffIdMap = new HashMap<>();

static {
EnumSet.allOf(Buffs.class).forEach(buff -> buffIdMap.put(buff.getBuffId(), buff));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public enum Units implements UnitType {
TERRAN_REAPER(49, SMART, MOVE, PATROL, HOLD_POSITION, EFFECT_KD8CHARGE, STOP, ATTACK),
TERRAN_REFINERY(20, CANCEL, HALT),
TERRAN_REFINERY_RICH(1943, CANCEL, HALT),
TERRAN_REFINERY_RICH_410(1960, CANCEL, HALT),
TERRAN_SCV(45, SMART, MOVE, PATROL, HOLD_POSITION, BUILD_COMMAND_CENTER, BUILD_SUPPLY_DEPOT, BUILD_REFINERY,
BUILD_BARRACKS, BUILD_ENGINEERING_BAY, BUILD_MISSILE_TURRET, BUILD_BUNKER, BUILD_SENSOR_TOWER,
BUILD_GHOST_ACADEMY, BUILD_FACTORY, BUILD_STARPORT, BUILD_ARMORY, BUILD_FUSION_CORE, HALT, STOP,
Expand Down Expand Up @@ -146,7 +145,6 @@ public enum Units implements UnitType {
RESEARCH_ZERG_MISSILE_WEAPONS),
ZERG_EXTRACTOR(88, CANCEL),
ZERG_EXTRACTOR_RICH(1981, CANCEL),
ZERG_EXTRACTOR_RICH_410(1956, CANCEL),
ZERG_GREATER_SPIRE(102, CANCEL_LAST, RESEARCH_ZERG_FLYER_ARMOR, RESEARCH_ZERG_FLYER_ATTACK),
ZERG_HATCHERY(86, SMART, MORPH_LAIR, RESEARCH_PNEUMATIZED_CARAPACE, RESEARCH_BURROW, TRAIN_QUEEN, CANCEL,
CANCEL_LAST, RALLY_UNITS, RALLY_WORKERS),
Expand Down Expand Up @@ -214,7 +212,6 @@ public enum Units implements UnitType {
PROTOSS_ARCHON(141, SMART, MOVE, PATROL, HOLD_POSITION, STOP, RALLY_UNITS, ATTACK),
PROTOSS_ASSIMILATOR(61, CANCEL),
PROTOSS_ASSIMILATOR_RICH(1980, CANCEL),
PROTOSS_ASSIMILATOR_RICH_410(1955, CANCEL),
PROTOSS_CARRIER(79, SMART, MOVE, PATROL, HOLD_POSITION, BUILD_INTERCEPTORS, STOP, CANCEL_LAST, ATTACK),
PROTOSS_COLOSSUS(4, SMART, MOVE, PATROL, HOLD_POSITION, STOP, ATTACK),
PROTOSS_CYBERNETICS_CORE(72, RESEARCH_WARP_GATE, CANCEL, CANCEL_LAST, RESEARCH_PROTOSS_AIR_ARMOR,
Expand Down Expand Up @@ -380,6 +377,31 @@ public static UnitType from(int sc2ApiUnitTypeId) {
return Optional.ofNullable(unitTypeIdMap.get(sc2ApiUnitTypeId)).orElse(Other.of(sc2ApiUnitTypeId));
}

public static void remapForBuild(Integer build) {
if (build >= 81009) {
updateId(1981, 1995);
updateId(1980, 1994);

updateId(1982, 1996);
updateId(1983, 1997);
updateId(1984, 1998);
} else if (build >= 75689) {
updateId(1943, 1960);
updateId(1981, 1956);
updateId(1980, 1955);

updateId(1982, 1961);
updateId(1983, 1962);
updateId(1984, 1963);
}
}

private static void updateId(int oldId, int newId) {
UnitType toUpdate = unitTypeIdMap.remove(oldId);
((Units) toUpdate).unitTypeId = newId;
unitTypeIdMap.put(newId, toUpdate);
}

@Override
public Integer toSc2Api() {
return getUnitTypeId();
Expand Down

0 comments on commit 482156d

Please sign in to comment.