code: async def build(self, building: UnitTypeId, near: Union[Point2, Point3], max_distance: int=20, unit: Optional[Unit]=None, random_alternative: bool=True, placement_step: int=2):
          
  
          if isinstance(near, Unit):
              near = near.position.to2
          elif near is not None:
              near = near.to2
          else:
              return
  
          p = await self.find_placement(building, near.rounded, max_distance, random_alternative, placement_step)
          if p is None:
              return ActionResult.CantFindPlacementLocation
  
          unit = unit or self.select_build_worker(p)
          if unit is None or not self.can_afford(building):
              return ActionResult.Error
          return await self.do(unit.build(building, p))
docs: Build a building.