Пример #1
0
def place():
  units = BoScript.allPlayerUnits(ai.player)
  for u in units:
    # AB; unitAdvanceWork(u) == 9 means "WorkPlugin", which is e.g. produce
    if BoScript.canUnitProduce(u) and BoScript.unitAdvanceWork(u) == 9 and BoScript.hasUnitCompletedProduction(u):
      boprint("debug", "start placement algorithm for unit %d" % u)
      placeUnit(u, BoScript.completedProductionType(u))
Пример #2
0
def advanceAttack():
    global aiunit, aitarget
    boprint("debug", "%s: advanceAttack()" % module)
    # check if target is still alive
    if aitarget == -1 or not BoScript.isUnitAlive(aitarget):
        boprint("debug", "searching for new target...")
        aitarget = findTarget()
        if aitarget == -1:
            boprint("debug", "... no target found. nothing to do.")
            return
    boprint("debug", "... target is now %s" % aitarget)

    # find attacker
    attacker = -1
    units = BoScript.allPlayerUnits(ai.player)
    while attacker == -1:
        aiunit = aiunit + 1
        if aiunit >= len(units):
            aiunit = -1
            boprint("info", "No attacker found, returning")
            return
        u = units[aiunit]
        if BoScript.isUnitMobile(u):
            if BoScript.canUnitShoot(
                    u) and not explorerObject.isIdExploring(u):
                attacker = u
    targetpos = BoScript.unitPosition(aitarget)
    boprint(
        "debug",
        "ordering unit %s to attack targetpos %s containing target %s" %
        (attacker, targetpos, aitarget))
    BoScript.moveUnitWithAttacking(attacker, targetpos[0], targetpos[1])
Пример #3
0
 def findExplorerUnit(self):
     units = BoScript.allPlayerUnits(self.mPlayer)
     for u in units:
         if BoScript.isUnitMobile(u):
             if BoScript.canUnitMineMinerals(u) or BoScript.canUnitMineOil(
                     u):
                 continue
             pos = BoScript.unitPosition(u)
             if pos[0] != -1:
                 return unit.Unit(self.mPlayer, u)
     return 0
Пример #4
0
def produce():
  units = BoScript.allPlayerUnits(ai.player)
  for u in units:
    # AB: unitAdvanceWork(u) == 0 means that the unit is idle
    if BoScript.canUnitProduce(u) and BoScript.unitAdvanceWork(u) == 0:
      boprint("debug", "start production algorithm for unit %d" % u)
      prod = BoScript.productionTypes(u)
      canProduceFacilities = 0
      canProduceMobiles = 0
      for p in prod:
        isMobile = BoScript.isUnitTypeMobile(ai.player, p)
        if isMobile:
          canProduceMobiles = 1
        else:
          canProduceFacilities = 1
      if canProduceFacilities:
        produceFacilities(u)
      if canProduceMobiles:
        produceMobiles(u)