python-sc2 icon indicating copy to clipboard operation
python-sc2 copied to clipboard

Document correct upgrade procedure for Terran buildings

Open hsalokor opened this issue 7 years ago • 5 comments

Terran buildings seemed to be fairly picky for applying upgrades. The correct way to do this seems to be like this:

if self.units(BARRACKSTECHLAB).ready.exists:
  for lab in self.units(BARRACKSTECHLAB).ready:
    abilities = await self.get_available_abilities(lab)
    if AbilityId.RESEARCH_COMBATSHIELD in abilities and \
       self.can_afford(AbilityId.RESEARCH_COMBATSHIELD):
       await self.do(lab(AbilityId.RESEARCH_COMBATSHIELD))

Add example for building the basic upgrades.

hsalokor avatar Feb 19 '18 10:02 hsalokor

could you also add example of building TECHLAB / BARRACKSTECHLAB

vgainullin avatar Jul 10 '18 10:07 vgainullin

@vgainullin You can do it like this

         for sp in self.units(STARPORT).ready:
         if sp.add_on_tag == 0:
           await self.do(sp.build(STARPORTTECHLAB))

You can check the existence of addon like this

def add_on_name(self, structure):
        if structure.add_on_tag != 0:
            return self.units.find_by_tag(structure.add_on_tag).name
        else:
            return "None"

e.g.

if ((len(barrack.orders) < 1) or (self.add_on_name(barrack) == "BarracksReactor" and len(barrack.orders) < 2)):
          await self.train_unit_try(barrack, MARINE)

alexander-kazakov avatar Jul 25 '18 18:07 alexander-kazakov

@alexander-kazakov I tried this 'add_on_tag' on the Command Center to check if the Command Center has Orbital Command. But failed, always got 0. Can it be using the same way to check on Command Center?

david-x-chen avatar Aug 16 '18 16:08 david-x-chen

Orbital command works differently. It actually converts the command center unit into orbital command one.

So all your code where you select command center will not work for orbital command. To interact with orbital command, just use a selector for units(orbital command constant)

alexander-kazakov avatar Aug 16 '18 16:08 alexander-kazakov

@alexander-kazakov Thanks!

david-x-chen avatar Aug 17 '18 14:08 david-x-chen