Skip to content

Commit f25668c

Browse files
committed
implement upgradetype
1 parent a56c077 commit f25668c

File tree

1 file changed

+168
-23
lines changed

1 file changed

+168
-23
lines changed

src/main/java/bwapi/types/UpgradeType.java

Lines changed: 168 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package bwapi.types;
22

3+
import java.util.Arrays;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
import static bwapi.types.Race.*;
8+
import static bwapi.types.UnitType.*;
9+
310
public enum UpgradeType {
411
Terran_Infantry_Armor(0),
512
Terran_Vehicle_Plating(1),
@@ -60,69 +67,207 @@ public enum UpgradeType {
6067
None(61),
6168
Unknown(62);
6269

63-
private int value;
70+
private int id;
6471

65-
public int getValue(){
66-
return value;
67-
}
68-
69-
UpgradeType(int value) {
70-
this.value = value;
72+
UpgradeType(int id) {
73+
this.id = id;
7174
}
7275

7376
public Race getRace() {
74-
return null;
77+
return upgradeRaces[id];
7578
}
7679

7780
public int mineralPrice() {
78-
return -1;
81+
return mineralPrice(1);
7982
}
8083

8184
public int mineralPrice(int level) {
82-
return -1;
85+
return defaultOreCostBase[id] + Math.max(0, level-1) * mineralPriceFactor();
8386
}
8487

8588
public int mineralPriceFactor() {
86-
return -1;
89+
return defaultOreCostFactor[id];
8790
}
8891

8992
public int gasPrice() {
90-
return -1;
93+
return mineralPrice();
9194
}
9295

9396
public int gasPrice(int level) {
94-
return -1;
97+
return mineralPrice(level);
9598
}
9699

97100
public int gasPriceFactor() {
98-
return -1;
101+
return mineralPriceFactor();
99102
}
100103

101104
public int upgradeTime() {
102-
return -1;
105+
return upgradeTime(1);
103106
}
104107

105108
public int upgradeTime(int level) {
106-
return -1;
109+
return defaultTimeCostBase[id] + Math.max(0, level-1) * upgradeTimeFactor();
107110
}
108111

109112
public int upgradeTimeFactor() {
110-
return -1;
113+
return defaultTimeCostFactor[id];
111114
}
112115

113-
public int maxRepeats() {
114-
return -1;
116+
public UnitType whatUpgrades() {
117+
return whatUpgrades[id];
115118
}
116119

117-
public UnitType whatUpgrades() {
118-
return null;
120+
public Set<UnitType> whatUses() {
121+
return Arrays.stream(upgradeWhatUses[id]).collect(Collectors.toSet());
122+
}
123+
124+
public int maxRepeats() {
125+
return defaultMaxRepeats[id];
119126
}
120127

121128
public UnitType whatsRequired() {
122-
return null;
129+
return whatsRequired(1);
123130
}
124131

125132
public UnitType whatsRequired(int level) {
126-
return null;
133+
return (level >= 1 && level <= 3) ? requirements[level-1][id] : UnitType.None;
127134
}
135+
136+
// DEFAULTS
137+
private static int defaultOreCostBase[] = { // same as default gas cost base
138+
100, 100, 150, 150, 150, 100, 150, 100, 100, 100, 100, 100, 100, 100, 100, 200, 150, 100, 200, 150, 100, 150, 200, 150, 200, 150, 150, 100, 200,
139+
150, 150, 150, 150, 150, 150, 200, 200, 200, 150, 150, 150, 100, 200, 100, 150, 0, 0, 100, 100, 150, 150, 150, 150, 200, 100, 0, 0, 0, 0, 0, 0, 0, 0
140+
};
141+
private static int defaultOreCostFactor[] = { // same as default gas cost factor
142+
75, 75, 75, 75, 75, 75, 75, 75, 75, 50, 50, 50, 75, 50, 75, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
144+
};
145+
private static int defaultTimeCostBase[] = {
146+
4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 1500, 1500, 0, 2500,
147+
2500, 2500, 2500, 2500, 2400, 2000, 2000, 1500, 1500, 1500, 1500, 2500, 2500, 2500, 2000, 2500, 2500, 2500, 2000,
148+
2000, 2500, 2500, 2500, 1500, 2500, 0, 0, 2500, 2500, 2500, 2500, 2500, 2000, 2000, 2000, 0, 0, 0, 0, 0, 0, 0, 0
149+
};
150+
private static int defaultTimeCostFactor[] = {
151+
480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
153+
};
154+
private static int defaultMaxRepeats[] = {
155+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
156+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0
157+
};
158+
159+
private static UnitType whatUpgrades[] = {
160+
Terran_Engineering_Bay, Terran_Armory, Terran_Armory, Zerg_Evolution_Chamber, Zerg_Spire, Protoss_Forge, Protoss_Cybernetics_Core, Terran_Engineering_Bay,
161+
Terran_Armory, Terran_Armory, Zerg_Evolution_Chamber, Zerg_Evolution_Chamber, Zerg_Spire, Protoss_Forge, Protoss_Cybernetics_Core, Protoss_Forge, Terran_Academy,
162+
Terran_Machine_Shop, UnitType.None, Terran_Science_Facility, Terran_Covert_Ops, Terran_Covert_Ops, Terran_Control_Tower, Terran_Physics_Lab, Zerg_Lair, Zerg_Lair, Zerg_Lair,
163+
Zerg_Spawning_Pool, Zerg_Spawning_Pool, Zerg_Hydralisk_Den, Zerg_Hydralisk_Den, Zerg_Queens_Nest, Zerg_Defiler_Mound, Protoss_Cybernetics_Core, Protoss_Citadel_of_Adun,
164+
Protoss_Robotics_Support_Bay, Protoss_Robotics_Support_Bay, Protoss_Robotics_Support_Bay, Protoss_Observatory, Protoss_Observatory, Protoss_Templar_Archives,
165+
Protoss_Fleet_Beacon, Protoss_Fleet_Beacon, Protoss_Fleet_Beacon, Protoss_Arbiter_Tribunal, UnitType.None, UnitType.None, Protoss_Fleet_Beacon, UnitType.None, Protoss_Templar_Archives,
166+
UnitType.None, Terran_Academy, Zerg_Ultralisk_Cavern, Zerg_Ultralisk_Cavern, Terran_Machine_Shop, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None
167+
};
168+
169+
private static UnitType requirements[][] = {
170+
// Level 1
171+
{
172+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
173+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, Zerg_Hive, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
174+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, Terran_Armory, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None
175+
},
176+
// Level 2
177+
{
178+
Terran_Science_Facility, Terran_Science_Facility, Terran_Science_Facility, Zerg_Lair, Zerg_Lair, Protoss_Templar_Archives, Protoss_Fleet_Beacon,
179+
Terran_Science_Facility, Terran_Science_Facility, Terran_Science_Facility, Zerg_Lair, Zerg_Lair, Zerg_Lair, Protoss_Templar_Archives,
180+
Protoss_Fleet_Beacon, Protoss_Cybernetics_Core, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
181+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
182+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None
183+
},
184+
// Level 3
185+
{
186+
Terran_Science_Facility, Terran_Science_Facility, Terran_Science_Facility, Zerg_Hive, Zerg_Hive, Protoss_Templar_Archives, Protoss_Fleet_Beacon,
187+
Terran_Science_Facility, Terran_Science_Facility, Terran_Science_Facility, Zerg_Hive, Zerg_Hive, Zerg_Hive, Protoss_Templar_Archives,
188+
Protoss_Fleet_Beacon, Protoss_Cybernetics_Core, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
189+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None,
190+
UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None, UnitType.None
191+
},
192+
};
193+
194+
private static UnitType _Infantry_Armor[] = { Terran_Marine, Terran_Ghost, Terran_SCV, Hero_Gui_Montag, Terran_Civilian, Hero_Sarah_Kerrigan,
195+
Hero_Jim_Raynor_Marine, Terran_Firebat, Terran_Medic, Hero_Samir_Duran, Hero_Alexei_Stukov };
196+
private static UnitType _Vehicle_Plating[] = { Terran_Vulture, Terran_Goliath, Terran_Siege_Tank_Tank_Mode, Hero_Alan_Schezar, Hero_Jim_Raynor_Vulture,
197+
Hero_Edmund_Duke_Tank_Mode, Hero_Edmund_Duke_Siege_Mode, Terran_Siege_Tank_Siege_Mode };
198+
private static UnitType _Ship_Plating[] = { Terran_Wraith, Terran_Science_Vessel, Terran_Dropship, Terran_Battlecruiser, Hero_Tom_Kazansky, Hero_Magellan,
199+
Hero_Arcturus_Mengsk, Hero_Hyperion, Hero_Norad_II, Terran_Valkyrie, Hero_Gerard_DuGalle };
200+
private static UnitType _Carapace[] = { Zerg_Larva, Zerg_Egg, Zerg_Zergling, Zerg_Hydralisk, Zerg_Ultralisk, Zerg_Broodling, Zerg_Drone, Zerg_Defiler,
201+
Hero_Torrasque, Zerg_Infested_Terran, Hero_Infested_Kerrigan, Hero_Unclean_One, Hero_Hunter_Killer, Hero_Devouring_One,
202+
Zerg_Cocoon, Zerg_Lurker_Egg, Zerg_Lurker, Hero_Infested_Duran };
203+
private static UnitType _Flyer_Carapace[] = { Zerg_Overlord, Zerg_Mutalisk, Zerg_Guardian, Zerg_Queen, Zerg_Scourge, Hero_Matriarch, Hero_Kukulza_Mutalisk,
204+
Hero_Kukulza_Guardian, Hero_Yggdrasill, Zerg_Devourer };
205+
private static UnitType _Protoss_Armor[] = { Protoss_Dark_Templar, Protoss_Dark_Archon, Protoss_Probe, Protoss_Zealot, Protoss_Dragoon, Protoss_High_Templar,
206+
Protoss_Archon, Hero_Dark_Templar, Hero_Zeratul, Hero_Tassadar_Zeratul_Archon, Hero_Fenix_Zealot, Hero_Fenix_Dragoon,
207+
Hero_Tassadar, Hero_Warbringer, Protoss_Reaver, Hero_Aldaris };
208+
private static UnitType _Protoss_Plating[] = { Protoss_Corsair, Protoss_Shuttle, Protoss_Scout, Protoss_Arbiter, Protoss_Carrier, Protoss_Interceptor, Hero_Mojo,
209+
Hero_Gantrithor, Protoss_Observer, Hero_Danimoth, Hero_Artanis, Hero_Raszagal };
210+
private static UnitType _Infantry_Weapons[] = { Terran_Marine, Hero_Jim_Raynor_Marine, Terran_Ghost, Hero_Sarah_Kerrigan, Terran_Firebat, Hero_Gui_Montag,
211+
Special_Wall_Flame_Trap, Special_Right_Wall_Flame_Trap, Hero_Samir_Duran, Hero_Alexei_Stukov, Hero_Infested_Duran };
212+
private static UnitType _Vehicle_Weapons[] = { Terran_Vulture, Hero_Jim_Raynor_Vulture, Terran_Goliath, Hero_Alan_Schezar, Terran_Siege_Tank_Tank_Mode,
213+
Terran_Siege_Tank_Siege_Mode, Hero_Edmund_Duke_Tank_Mode, Hero_Edmund_Duke_Siege_Mode, Special_Floor_Missile_Trap,
214+
Special_Floor_Gun_Trap, Special_Wall_Missile_Trap, Special_Right_Wall_Missile_Trap };
215+
private static UnitType _Ship_Weapons[] = { Terran_Wraith, Hero_Tom_Kazansky, Terran_Battlecruiser, Hero_Hyperion, Hero_Norad_II, Hero_Arcturus_Mengsk,
216+
Hero_Gerard_DuGalle, Terran_Valkyrie };
217+
private static UnitType _Zerg_MeleeAtk[] = { Zerg_Zergling, Hero_Devouring_One, Hero_Infested_Kerrigan, Zerg_Ultralisk, Hero_Torrasque, Zerg_Broodling };
218+
private static UnitType _Zerg_RangeAtk[] = { Zerg_Hydralisk, Hero_Hunter_Killer, Zerg_Lurker };
219+
private static UnitType _Zerg_FlyerAtk[] = { Zerg_Mutalisk, Hero_Kukulza_Mutalisk, Hero_Kukulza_Guardian, Zerg_Guardian, Zerg_Devourer };
220+
private static UnitType _Protoss_GrndWpn[] = { Protoss_Zealot, Hero_Fenix_Zealot, Protoss_Dragoon, Hero_Fenix_Dragoon, Hero_Tassadar, Hero_Aldaris, Protoss_Archon,
221+
Hero_Tassadar_Zeratul_Archon, Hero_Dark_Templar, Hero_Zeratul, Protoss_Dark_Templar };
222+
private static UnitType _Protoss_AirWpn[] = { Protoss_Scout, Hero_Mojo, Protoss_Arbiter, Hero_Danimoth, Protoss_Interceptor, Protoss_Carrier, Protoss_Corsair, Hero_Artanis };
223+
private static UnitType _Shields[] = { Protoss_Corsair, Protoss_Dark_Templar, Protoss_Dark_Archon, Protoss_Probe, Protoss_Zealot, Protoss_Dragoon, Protoss_High_Templar,
224+
Protoss_Archon, Protoss_Shuttle, Protoss_Scout, Protoss_Arbiter, Protoss_Carrier, Protoss_Interceptor, Hero_Dark_Templar,
225+
Hero_Zeratul, Hero_Tassadar_Zeratul_Archon, Hero_Fenix_Zealot, Hero_Fenix_Dragoon, Hero_Tassadar, Hero_Mojo, Hero_Warbringer,
226+
Hero_Gantrithor, Protoss_Reaver, Protoss_Observer, Hero_Danimoth, Hero_Aldaris, Hero_Artanis, Hero_Raszagal };
227+
private static UnitType Shells[] = { Terran_Marine };
228+
private static UnitType _Ion_Thrusters[] = { Terran_Vulture };
229+
private static UnitType _Titan_Reactor[] = { Terran_Science_Vessel };
230+
private static UnitType _Ghost_Upgrades[] = { Terran_Ghost };
231+
private static UnitType _Apollo_Reactor[] = { Terran_Wraith };
232+
private static UnitType _Colossus_Reactor[] = { Terran_Battlecruiser };
233+
private static UnitType _Overlord_Upgrades[] = { Zerg_Overlord };
234+
private static UnitType _Zergling_Upgrades[] = { Zerg_Zergling };
235+
private static UnitType _Hydralisk_Upgrades[] = { Zerg_Hydralisk };
236+
private static UnitType _Gamete_Meiosis[] = { Zerg_Queen };
237+
private static UnitType _Metasynaptic_Node[] = { Zerg_Defiler };
238+
private static UnitType _Singularity_Charge[] = { Protoss_Dragoon };
239+
private static UnitType _Leg_Enhancements[] = { Protoss_Zealot };
240+
private static UnitType _Reaver_Upgrades[] = { Protoss_Reaver };
241+
private static UnitType _Gravitic_Drive[] = { Protoss_Shuttle };
242+
private static UnitType _Observer_Upgrades[] = { Protoss_Observer };
243+
private static UnitType _Khaydarin_Amulet[] = { Protoss_High_Templar };
244+
private static UnitType _Scout_Upgrades[] = { Protoss_Scout };
245+
private static UnitType _Carrier_Capacity[] = { Protoss_Carrier };
246+
private static UnitType _Khaydarin_Core[] = { Protoss_Arbiter };
247+
private static UnitType _Argus_Jewel[] = { Protoss_Corsair };
248+
private static UnitType _Argus_Talisman[] = { Protoss_Dark_Archon };
249+
private static UnitType _Caduceus_Reactor[] = { Terran_Medic };
250+
private static UnitType _Ultralisk_Upgrades[] = { Zerg_Ultralisk };
251+
private static UnitType _Charon_Boosters[] = { Terran_Goliath };
252+
253+
private static UnitType _Upgrade60[] = { Terran_Vulture_Spider_Mine, Critter_Ursadon, Critter_Scantid, Critter_Rhynadon, Critter_Ragnasaur, Critter_Kakaru, Critter_Bengalaas,
254+
Special_Cargo_Ship, Special_Mercenary_Gunship, Terran_SCV, Protoss_Probe, Zerg_Drone, Zerg_Infested_Terran, Zerg_Scourge };
255+
256+
private static UnitType upgradeWhatUses[][] = {
257+
_Infantry_Armor, _Vehicle_Plating, _Ship_Plating, _Carapace, _Flyer_Carapace, _Protoss_Armor, _Protoss_Plating,
258+
_Infantry_Weapons, _Vehicle_Weapons, _Ship_Weapons, _Zerg_MeleeAtk, _Zerg_RangeAtk, _Zerg_FlyerAtk, _Protoss_GrndWpn,
259+
_Protoss_AirWpn, _Shields, Shells, _Ion_Thrusters, {}, _Titan_Reactor, _Ghost_Upgrades, _Ghost_Upgrades,
260+
_Apollo_Reactor, _Colossus_Reactor, _Overlord_Upgrades, _Overlord_Upgrades, _Overlord_Upgrades, _Zergling_Upgrades,
261+
_Zergling_Upgrades, _Hydralisk_Upgrades, _Hydralisk_Upgrades, _Gamete_Meiosis, _Metasynaptic_Node, _Singularity_Charge,
262+
_Leg_Enhancements, _Reaver_Upgrades, _Reaver_Upgrades, _Gravitic_Drive, _Observer_Upgrades, _Observer_Upgrades,
263+
_Khaydarin_Amulet, _Scout_Upgrades, _Scout_Upgrades, _Carrier_Capacity, _Khaydarin_Core, {}, {},
264+
_Argus_Jewel, {}, _Argus_Talisman, {}, _Caduceus_Reactor, _Ultralisk_Upgrades, _Ultralisk_Upgrades,
265+
_Charon_Boosters, {}, {}, {}, {}, {}, _Upgrade60, {}, {}
266+
};
267+
268+
private static Race upgradeRaces[] = {
269+
Terran, Terran, Terran, Zerg, Zerg, Protoss, Protoss, Terran, Terran, Terran, Zerg, Zerg, Zerg, Protoss, Protoss, Protoss, Terran, Terran, Terran, Terran, Terran,
270+
Terran, Terran, Terran, Zerg, Zerg, Zerg, Zerg, Zerg, Zerg, Zerg, Zerg, Zerg, Protoss, Protoss, Protoss, Protoss, Protoss, Protoss, Protoss, Protoss, Protoss,
271+
Protoss, Protoss, Protoss, Race.None, Race.None, Protoss, Race.None, Protoss, Race.None, Terran, Zerg, Zerg, Terran, Race.None, Race.None, Race.None, Race.None, Race.None, Race.None, Race.None, Race.Unknown
272+
};
128273
}

0 commit comments

Comments
 (0)