Commit 2a1739c5 authored by m1ndgames's avatar m1ndgames

update

parent 8b3e7ffc
{
"Bots": {
"m1ndb0t-2.0": {
"Race": "Protoss",
"Race": "Random",
"Type": "Python",
"RootPath": "./",
"FileName": "run.py"
......
......@@ -26,11 +26,11 @@ class m1ndb0t(sc2.BotAI):
# STDOUT
self.showstatus = False
async def on_start(self):
await self.gamemanager.startGame()
async def on_step(self, iteration):
"""Runs on every Gamestep"""
if iteration == 0:
await self.gamemanager.startGame()
self.iteration = iteration
# Manage own and enemy Race
......@@ -67,13 +67,5 @@ class m1ndb0t(sc2.BotAI):
self.do(unit.attack(target))
return
#for worker in self.workers:
# print("----")
# print(str(worker))
# print(str(worker.orders))
# print("----")
# break
#TODO: Fix
# async def on_end(self):
# await self.warmanager.savewinningstrategy()
async def on_end(self):
await self.warmanager.savewinningstrategy()
import random
from strategies.protoss.StalkerRush import *
from strategies.protoss.ZealotRush import *
from strategies.protoss.SkyToss import *
from strategies.protoss.DarkTemplar import *
class ProtossManager():
"""Protoss Race Manager"""
......@@ -17,10 +19,14 @@ class ProtossManager():
def pickStrategy(self):
strategies = [
ZealotRush(self.bot),
StalkerRush(self.bot)
StalkerRush(self.bot),
SkyToss(self.bot),
DarkTemplar(self.bot)
]
self.strategy = random.choice(strategies)
# DEBUG Overrides
#self.strategy = StalkerRush(self.bot)
#self.strategy = ZealotRush(self.bot)
#self.strategy = SkyToss(self.bot)
#self.strategy = DarkTemplar(self.bot)
from sc2.constants import *
from sc2 import race_worker
class DarkTemplar:
"""Protoss DarkTemplar"""
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'dark_templar'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
await self.Macro()
await self.Micro()
await self.Buffs()
async def Macro(self):
"""Macro Routine"""
await self.bot.ressources.createGas()
#await self.createWall()
await self.bot.unitmanager.createBuilding("DarkShrine", 1, self.bot.hq_location, 20)
await self.bot.unitmanager.createUnit("Adept", 3)
if self.bot.townhalls.amount <= 2:
await self.bot.unitmanager.createBuilding("Gateway", 3, self.bot.hq_location, 20)
if self.bot.townhalls.amount >= 3:
await self.bot.unitmanager.createBuilding("Gateway", 4, self.bot.hq_location, 20)
if self.bot.townhalls.ready.amount >= 3:
await self.bot.unitmanager.createBuilding("Gateway", self.bot.townhalls.ready.amount, self.bot.hq_location, 30)
await self.bot.unitmanager.trainSkill("RESEARCH_WARPGATE")
await self.bot.unitmanager.createUnit("DarkTemplar", 100)
# Send a worker scout
if self.bot.units(race_worker[self.bot.race]).ready and not self.workerscout:
worker = self.bot.units(race_worker[self.bot.race]).ready.first
if worker:
self.workerscout = True
await self.bot.warmanager.scout(worker)
# Check if expansion is needed
if (self.bot.units(race_worker[self.bot.race]).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 240 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 600 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
"""Micro Routine"""
# DT Micro
darktemplars = self.bot.units(UnitTypeId.DARKTEMPLAR).ready
if darktemplars:
ground_enemies = self.bot.enemy_units.not_flying
if ground_enemies:
for darktemplar in darktemplars:
near_enemies = ground_enemies.closer_than(30, darktemplar)
if near_enemies:
next_enemy = near_enemies.closest_to(darktemplar)
distance2enemy = darktemplar.distance_to(next_enemy)
if distance2enemy < 20:
self.bot.do(darktemplar.attack(next_enemy))
async def Buffs(self):
"""Buff Routine"""
# Morph Gateway to Warpgate if possible
if self.bot.units(UnitTypeId.GATEWAY).ready:
gateways = self.bot.units(UnitTypeId.GATEWAY).ready
for gateway in gateways:
abilities = await self.bot.get_available_abilities(gateway)
if AbilityId.MORPH_WARPGATE in abilities and self.bot.can_afford(AbilityId.MORPH_WARPGATE):
self.bot.do(gateway(AbilityId.MORPH_WARPGATE))
# Chronoboost
for hq in self.bot.townhalls.ready:
# Boost Cyber Core
if self.bot.units(UnitTypeId.CYBERNETICSCORE).ready.exists and not self.coreboosted:
ccore = self.bot.units(UnitTypeId.CYBERNETICSCORE).ready.first
if not ccore.has_buff(BuffId.CHRONOBOOSTENERGYCOST):
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.EFFECT_CHRONOBOOSTENERGYCOST in abilities:
self.bot.do(hq(AbilityId.EFFECT_CHRONOBOOSTENERGYCOST, ccore))
self.coreboosted = True
return
# Boost Gateway
if self.bot.units(UnitTypeId.GATEWAY).ready.exists and self.bot.units(UnitTypeId.CYBERNETICSCORE).ready.exists:
gw = self.bot.units(UnitTypeId.GATEWAY).ready.first
if not gw.has_buff(BuffId.CHRONOBOOSTENERGYCOST):
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.EFFECT_CHRONOBOOSTENERGYCOST in abilities:
self.bot.do(hq(AbilityId.EFFECT_CHRONOBOOSTENERGYCOST, gw))
return
# Boost Warpgate
if self.bot.units(UnitTypeId.WARPGATE).ready.exists and self.bot.units(UnitTypeId.CYBERNETICSCORE).ready.exists:
warps = self.bot.units(UnitTypeId.WARPGATE).ready.first
if not warps.has_buff(BuffId.CHRONOBOOSTENERGYCOST):
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.EFFECT_CHRONOBOOSTENERGYCOST in abilities:
self.bot.do(hq(AbilityId.EFFECT_CHRONOBOOSTENERGYCOST, warps))
return
async def createWall(self):
"""Wall-in Routine"""
await self.bot.ressources.createGas()
rampsupplybuildposition = self.bot.ramp_location
if self.bot.structures(UnitTypeId.PYLON).ready.exists:
rampsupply = self.bot.structures.filter(lambda w: w.type_id == UnitTypeId.PYLON).closer_than(5, rampsupplybuildposition)
if rampsupply:
self.ramp_supply_built = True
else:
self.ramp_supply_built = False
await self.bot.unitmanager.createSupply(rampsupplybuildposition, 0, True)
if self.ramp_supply_built:
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.PHOTONCANNON)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 3}
if len(depot_placement_positions) == 0:
return
target_depot_location = depot_placement_positions.pop()
await self.bot.unitmanager.createBuilding("PhotonCannon", 2, target_depot_location, 0, True)
if depots.ready:
await self.bot.unitmanager.createBuilding("ShieldBattery", 1, rampsupplybuildposition, 7, True)
\ No newline at end of file
from sc2.constants import *
from sc2 import race_worker
class SkyToss:
"""Protoss SkyToss"""
def __init__(self, bot=None):
self.bot = bot
self.ramp_supply_built = False
self.workerscout = None
self.bot.strategy = 'sky_toss'
self.bot.squadsize = 10
async def Run(self):
"""Runs on every GameStep"""
if int(self.bot.time) <= 360:
self.bot.attack_count = 5
self.bot.retreat_count = 1
elif int(self.bot.time) > 360:
self.bot.attack_count = 10
self.bot.retreat_count = 3
elif int(self.bot.time) >= 600:
self.bot.attack_count = 15
self.bot.retreat_count = 5
await self.Macro()
await self.Micro()
async def Macro(self):
"""Macro Routine"""
await self.createWall()
await self.bot.ressources.createGas()
await self.bot.unitmanager.createBuilding("Stargate", 3, self.bot.hq_location, 15)
await self.bot.unitmanager.createUnit("Adept", 5)
await self.bot.unitmanager.createUnit("Carrier", 10)
await self.bot.unitmanager.createUnit("VoidRay", 10)
await self.bot.unitmanager.createUnit("Mothership", 1)
await self.bot.unitmanager.createUnit("Tempest", 3)
# Send a worker scout
if self.bot.units(race_worker[self.bot.race]).ready and not self.workerscout:
worker = self.bot.units(race_worker[self.bot.race]).ready.first
if worker:
self.workerscout = True
await self.bot.warmanager.scout(worker)
# Check if expansion is needed
if (self.bot.units(race_worker[self.bot.race]).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 120 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 360 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
"""Micro Routine"""
# Adept
adepts = self.bot.units(UnitTypeId.ADEPT).ready
if adepts:
for adept in adepts:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, adept)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(adept, e):
closeenemies.remove(e)
if not closeenemies:
break
next_enemy = closeenemies.closest_to(adept)
if not next_enemy:
break
distance2enemy = adept.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(adept.attack(next_enemy))
nx = self.bot.townhalls.ready.closest_to(adept)
if not nx:
break
nxdistance = adept.position.distance_to(nx.position)
if nxdistance < 10:
break
async def createWall(self):
"""Wall-in Routine"""
await self.bot.ressources.createGas()
rampsupplybuildposition = self.bot.ramp_location
if self.bot.structures(UnitTypeId.PYLON).ready.exists:
rampsupply = self.bot.structures.filter(lambda w: w.type_id == UnitTypeId.PYLON).closer_than(5, rampsupplybuildposition)
if rampsupply:
self.ramp_supply_built = True
else:
self.ramp_supply_built = False
await self.bot.unitmanager.createSupply(rampsupplybuildposition, 0, True)
if self.ramp_supply_built:
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.PHOTONCANNON)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 3}
if len(depot_placement_positions) == 0:
return
target_depot_location = depot_placement_positions.pop()
await self.bot.unitmanager.createBuilding("PhotonCannon", 2, target_depot_location, 0, True)
if depots.ready:
await self.bot.unitmanager.createBuilding("ShieldBattery", 1, rampsupplybuildposition, 7, True)
\ No newline at end of file
......@@ -9,19 +9,11 @@ class ZealotRush:
self.workerscout = None
self.bot.strategy = 'zealot_rush'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
if int(self.bot.time) <= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 600:
self.bot.attack_count = 1
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
......@@ -30,9 +22,12 @@ class ZealotRush:
if self.bot.townhalls.amount <= 2:
await self.bot.unitmanager.createBuilding("Gateway", 3, self.bot.hq_location, 15)
if self.bot.townhalls.amount >= 3:
await self.bot.unitmanager.createBuilding("Gateway", 6, self.bot.hq_location, 15)
await self.bot.unitmanager.createBuilding("Gateway", 6, self.bot.hq_location, 20)
if self.bot.townhalls.ready.amount >= 3:
await self.bot.unitmanager.createBuilding("Gateway", self.bot.townhalls.ready.amount * 2, self.bot.hq_location, 30)
await self.bot.unitmanager.createUnit("Zealot", 50)
await self.bot.unitmanager.createUnit("Zealot", 100)
# Send a worker scout
if self.bot.units(race_worker[self.bot.race]).ready and not self.workerscout:
......@@ -45,9 +40,9 @@ class ZealotRush:
if (self.bot.units(race_worker[self.bot.race]).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 300 and self.bot.townhalls.amount == 1:
if int(self.bot.time) >= 180 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 600 and self.bot.townhalls.amount <= 3:
if int(self.bot.time) >= 300 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
......
......@@ -9,38 +9,20 @@ class ZerglingRush:
self.workerscout = None
self.bot.strategy = 'zergling_rush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
if int(self.bot.time) <= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 600:
self.bot.attack_count = 1
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
await self.Buffs()
async def Macro(self):
"""Macro Routine"""
spawningpoolscount = self.bot.townhalls.amount * 3
if spawningpoolscount == 0:
spawningpoolscount = 1
await self.bot.unitmanager.createUnit("Zergling", 100)
await self.bot.unitmanager.createUnit("Queen", self.bot.townhalls.amount)
# Send a worker scout
if self.bot.units(race_worker[self.bot.race]).ready and not self.workerscout:
worker = self.bot.units(race_worker[self.bot.race]).ready.first
if worker:
self.workerscout = True
await self.bot.warmanager.scout(worker)
if self.bot.townhalls.ready.amount >= 3:
await self.bot.unitmanager.createUnit("Queen", self.bot.townhalls.ready.amount)
await self.bot.warmanager.expand()
......@@ -54,6 +36,12 @@ class ZerglingRush:
closeenemies = enemies.closer_than(30, zergling)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(zergling, e):
closeenemies.remove(e)
if not closeenemies:
break
next_enemy = closeenemies.closest_to(zergling)
if not next_enemy:
break
......@@ -70,52 +58,22 @@ class ZerglingRush:
if nxdistance < 10:
break
if distance2enemy < self.bot.techtree.get_unit_weaponrange(UnitTypeId.ZERGLING):
if (next_enemy.name != 'Probe') or (next_enemy.name != 'SCV') or (
next_enemy.name != 'Drone'):
if distance2enemy < 2:
break
else:
moveposition = zergling.position.towards(next_enemy.position, -1)
if not moveposition or not self.bot.in_pathing_grid(moveposition):
break
self.bot.do(zergling.move(moveposition))
# queen
zerglings = self.bot.units(UnitTypeId.QUEEN).ready
if zerglings:
for queen in zerglings:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, queen)
if closeenemies:
next_enemy = closeenemies.closest_to(queen)
if not next_enemy:
break
distance2enemy = queen.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(queen.attack(next_enemy))
nx = self.bot.townhalls.ready.closest_to(queen)
if not nx:
break
nxdistance = queen.position.distance_to(nx.position)
if nxdistance < 10:
break
queens = self.bot.units(UnitTypeId.QUEEN).ready
if queens:
for queen in queens:
hqs = self.bot.structures(UnitTypeId.HATCHERY)
for hq in hqs:
q = self.bot.units.filter(lambda unit: unit.type_id == UnitTypeId.QUEEN and unit.is_ready and (unit.is_idle or unit.orders[0].ability.id != AbilityId.EFFECT_INJECTLARVA))
if not q:
self.bot.do(queen.move(hq.position))
break
nearhq = self.bot.structures.closer_than(5, queen.position).filter(lambda w: w.type_id in [UnitTypeId.HATCHERY])
if nearhq:
abilities = await self.bot.get_available_abilities(queen)
if AbilityId.EFFECT_INJECTLARVA in abilities:
self.bot.do(queen(AbilityId.EFFECT_INJECTLARVA, nearhq[0]))
if distance2enemy < self.bot.techtree.get_unit_weaponrange(UnitTypeId.QUEEN):
if (next_enemy.name != 'Probe') or (next_enemy.name != 'SCV') or (
next_enemy.name != 'Drone'):
if distance2enemy < 2:
break
else:
moveposition = queen.position.towards(next_enemy.position, -1)
if not moveposition or not self.bot.in_pathing_grid(moveposition):
break
self.bot.do(queen.move(moveposition))
async def Buffs(self):
return
......@@ -59,6 +59,33 @@ class TechTree():
else:
return 0
def can_attack(self, unit, enemyunit):
unittype = unit.type_id
unitname = self.get_name_from_id(unittype.value)
target_type = None
for unit in self.unit:
if unit['name'] == unitname:
if 'weapons' in unit:
for weapon in unit['weapons']:
if 'target_type' in weapon:
target_type = weapon['target_type']
if target_type == 'Ground':
if not enemyunit.is_flying:
return 1
else:
return 0
elif target_type == 'Air':
if enemyunit.is_flying:
return 1
else:
return 0
elif target_type == 'Any':
return 1
else:
return 0
def get_supplycost(self, name):
for unit in self.unit:
if unit['name'] == name:
......
......@@ -18,6 +18,3 @@ class TerranManager():
MarineRush(self.bot)
]
self.strategy = random.choice(strategies)
# DEBUG Overrides
self.strategy = MarineRush(self.bot)
......@@ -157,7 +157,7 @@ class UnitManager():
print("Building supply: " + str(buildingname))
self.bot.do(worker.build(building, supplyposition))
async def createBuilding(self, buildingname, count, position, maxrange=15, force=False):
async def createBuilding(self, buildingname, count, position, maxrange=30, force=False):
"""Builds everything required for a Building / Builds a Building"""
buildingid = self.bot.techtree.get_id_from_name(buildingname)
buildingcount = self.bot.structures(buildingid).amount
......@@ -174,7 +174,7 @@ class UnitManager():
if not self.bot.structures(requirementbuildingid).exists:
if not self.bot.already_pending(requirementbuildingid):
requirementbuildingname = self.bot.techtree.get_name_from_id(requirementbuildingid.value)
await self.createBuilding(requirementbuildingname, 1, self.bot.hq_location, 15)
await self.createBuilding(requirementbuildingname, 1, self.bot.hq_location, 30)
return
# Return if there is no worker available
......@@ -211,26 +211,26 @@ class UnitManager():
if not p:
return
closebuildings = self.bot.structures.filter(lambda w: w.distance_to(randomposition) <= 4)
closebuildings = self.bot.structures.filter(lambda w: w.distance_to(randomposition) <= 3)
if closebuildings and force == False:
return
# Make sure its not build close to the ramp
randompositiondistancetoramp = randomposition.distance_to(self.bot.ramp_location)
if randompositiondistancetoramp <= 7 and force == False:
if randompositiondistancetoramp <= 6 and force == False:
return
# Make sure its not build close to minerals
nextmineral = self.bot.mineral_field.closest_to(randomposition)
mineral_distance2buildplace = nextmineral.position.distance_to(randomposition)
if mineral_distance2buildplace <= 7:
if mineral_distance2buildplace <= 6:
return
# Make sure its not build close to gas
if self.bot.gas_buildings.exists:
nextgas = self.bot.gas_buildings.closest_to(randomposition)
gas_distance2buildplace = nextgas.position.distance_to(randomposition)
if gas_distance2buildplace <= 7:
if gas_distance2buildplace <= 6:
return
# Protoss specific
......
......@@ -36,18 +36,16 @@ class WarManager():
self.mineral_worker = None
async def Run(self):
await self.estimate()
await self.estimate_status()
if self.bot.iteration & 2 == 0:
await self.estimate()
await self.estimate_status()
await self.check_retreat()
await self.counterattack()
await self.commanderroutine()
await self.fightroutine()
await self.defendroutine()
await self.counterworkerrush()
if self.bot.iteration & 2 == 0:
await self.estimate()
await self.estimate_status()
await self.defendroutine()
if self.bot.showstatus:
if int(self.bot.time) & 2 == 0:
......@@ -77,7 +75,7 @@ class WarManager():
self.my_armypower_older = self.my_armypower
self.enemy_armypower = 0
enemies = self.bot.enemy_units.not_structure.filter(lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE])
enemies = self.bot.enemy_units.not_structure.filter(lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.LARVA])
for e in enemies:
self.enemy_armypower = self.enemy_armypower + 1
......@@ -93,7 +91,7 @@ class WarManager():
for n in self.bot.townhalls:
hqpositions.append(n.position)
enemies = self.bot.enemy_units.not_structure.filter(lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE])
enemies = self.bot.enemy_units.not_structure.filter(lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.LARVA])
enemiesattacking = 0
for e in enemies:
for n in hqpositions:
......@@ -131,8 +129,7 @@ class WarManager():
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [
UnitTypeId.OBSERVER] and w.type_id not in [UnitTypeId.WARPPRISM] and w.type_id not in [
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [
UnitTypeId.DARKTEMPLAR] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA])
for fighter in fighters:
distance2ramp = fighter.position.distance_to(self.bot.ramp_location)
......@@ -169,7 +166,7 @@ class WarManager():
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
UnitTypeId.OBSERVER] and w.type_id not in [UnitTypeId.WARPPRISM] and w.type_id not in [
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.DARKTEMPLAR] and w.type_id not in [UnitTypeId.SENTRY] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.SENTRY] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN])
if (fighters.amount >= self.bot.attack_count) or self.startcounter:
self.fightstarted = True
......@@ -193,8 +190,16 @@ class WarManager():
return
async def defendroutine(self):
"""Reacts to enemies around the Nexuses"""
hqs = self.bot.structures(UnitTypeId.NEXUS)
"""Reacts to enemies around the HQ"""
townhall = None
if self.bot.race_self == 'Protoss':
townhall = UnitTypeId.NEXUS
elif self.bot.race_self == 'Terran':
townhall = UnitTypeId.COMMANDCENTER
elif self.bot.race_self == 'Zerg':
townhall = UnitTypeId.HATCHERY
hqs = self.bot.structures(townhall)
for hq in hqs:
if self.bot.enemy_units:
enemies = self.bot.enemy_units.closer_than(30, hq)
......@@ -202,16 +207,20 @@ class WarManager():
if enemies:
self.attacked = True
self.my_status = 'Defend'
next_enemy = self.bot.enemy_units.closest_to(hq)
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
UnitTypeId.OBSERVER] and w.type_id not in [UnitTypeId.WARPPRISM] and w.type_id not in [
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [
UnitTypeId.DARKTEMPLAR] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.LARVA])
for fighter in fighters:
self.bot.do(fighter.attack(next_enemy.position))
unit_enemies = self.bot.enemy_units.closer_than(30, hq)
for e in unit_enemies:
if not self.bot.techtree.can_attack(fighter, e):
unit_enemies.remove(e)
if unit_enemies:
next_enemy = unit_enemies.closest_to(hq)
self.bot.do(fighter.attack(next_enemy.position))