Dentosal / python-sc2

A StarCraft II bot api client library for Python 3
MIT License
586 stars 182 forks source link

how to relocate terran flyable building for a proper addon #198

Closed ceacar closed 5 years ago

ceacar commented 5 years ago

I wrote some code below, doesn't work well

if self.units(UnitTypeId.FACTORY).ready.exists:
    fac = self.units(UnitTypeId.FACTORY).ready.first
    if fac:
        await self.do(fac(AbilityId.LIFT))
        print("try moving to landing point:", fac.add_on_land_position)
        # await self.do(fac(AbilityId.MOVE, fac.add_on_land_position))
        await self.do(fac(AbilityId.LAND, fac.add_on_land_position))

does any one have a solution

tweakimp commented 5 years ago

you are trying to lift and land at the same frame when a factory is ready. a landed factory does not have the ability land you have to lift, and then check for flying factory in the next frame. then make it land

ceacar commented 5 years ago

thanks lot; i m posting my code below in case anybody need it

async def relocate_building_for_addon(self, building_type:'UnitTypeId.BARRACKS', flying_building_type:'UnitTypeId.BARRACKSFLYING'):
    for unit in self.units(building_type).ready:
        if unit.add_on_tag == 0:
            await self.do(unit(AbilityId.LIFT))

    for unit in self.units(flying_building_type).ready:
        await self.do(unit(AbilityId.LAND, unit.add_on_land_position))
        await asyncio.sleep(5)