Guest User

Nick's Ace of Coders code

a guest
Oct 21st, 2015
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pointsMap = self.getControlPointsMap()
  2.  
  3. towardsB = Vector.add(self.pos, Vector.limit(Vector.subtract(pointsMap.nearB.pos, self.pos), 4.5))
  4. self.buildXY("archer", towardsB.x, towardsB.y)
  5. self.command(self.built[0], "move", pointsMap.nearB.pos)
  6. towardsA = Vector.add(self.pos, Vector.limit(Vector.subtract(pointsMap.nearA.pos, self.pos), 4.5))
  7. self.buildXY("archer", towardsA.x, towardsA.y)
  8. self.command(self.built[1], "move", pointsMap.nearA.pos)
  9.  
  10. centerPos = self.getControlPointsMap().center.pos
  11. self.hurl(self, centerPos)
  12. loop:
  13.     missiles = [m for m in self.findEnemyMissiles() if m.type is 'shell' and m.velocity.z < 0 or m.type is 'boulder']
  14.     missiles = missiles.concat([m for m in self.findFriendlyMissiles() if m.type is 'shell' and m.velocity.z < 0])
  15.     buildArmy(missiles)
  16.     commandArmy(missiles)
  17.     controlHero()
  18.  
  19. def buildArmy(missiles):
  20.     for missile in missiles:
  21.         # Don't build if a boulder/shell is about to land
  22.         if self.distanceTo(missile.targetPos) < 10:
  23.             return
  24.     type = "archer"
  25.     enemyArtillery = [a for a in self.findByType("artillery", self.findEnemies()) if self.distanceTo(a) > 25 and a.health > 60]
  26.     enemyTowers = self.findByType("arrow-tower", self.findEnemies())
  27.     nearestTower = self.findNearest(enemyTowers)
  28.     if not len(self.findByType("artillery", self.findFriends())) and (len(enemyArtillery) or len(enemyTowers) > 1 and nearestTower.health > 400 and self.distanceTo(nearestTower) > 10):
  29.         type = 'artillery'
  30.     if self.gold >= self.costOf(type):
  31.         #self.summon(type)
  32.         buildPos = Vector.add(self.pos, Vector.limit(Vector.subtract(centerPos, self.pos), 4.5))  # towards center
  33.         enemyHero = self.findByType("goliath")[0]
  34.         if enemyHero and buildPos.distance(enemyHero.pos) < 10:
  35.             awayFromEnemyHero = Vector.limit(Vector.subtract(self.pos, enemyHero.pos), 4.5)
  36.             if enemyHero.distanceTo(centerPos) < self.distanceTo(centerPos):
  37.                 # We will probably fling hero towards where we would otherwise build the unit soon, so rotate it
  38.                 angle = Math.PI / 2
  39.                 if len(self.built) % 2:
  40.                     angle *= -1
  41.                 awayFromEnemyHero = Vector.rotate(awayFromEnemyHero, angle)
  42.             buildPos = Vector.add(self.pos, awayFromEnemyHero)
  43.         if type is 'artillery':
  44.             self.summon(type)
  45.         else:
  46.             self.buildXY(type, buildPos.x, buildPos.y)
  47.  
  48. def commandArmy(missiles):
  49.     friends = self.built
  50.     enemies = self.findEnemies()
  51.     enemyHero = self.findByType("goliath")[0]
  52.     archers = self.findByType("archer", enemies)
  53.     artillery = self.findByType("artillery", enemies)
  54.     towers = self.findByType("arrow-tower", enemies)
  55.     soldiers = self.findByType("soldier", enemies)
  56.     points = self.getControlPoints()
  57.     for i, friend in enumerate(friends):
  58.         if friend.health <= 0: continue
  59.         if self.health < 1500 and enemyHero and (self.health < enemyHero.health + 500 or enemyHero.health < 750) and (friend.type != 'arrow-tower' or friend.distanceTo(enemyHero) < 30):
  60.             self.command(friend, "attack", enemyHero)
  61.             continue
  62.         if i < 2:
  63.             target = friend.findNearestEnemy()
  64.             if target and target.distanceTo(friend) < 25:
  65.                 self.command(friend, "attack", target)
  66.             else:
  67.                 self.command(friend, "move", points[i + 1].pos)
  68.             continue
  69.         tower = friend.findNearest(towers)
  70.         enemyArtillery = friend.findNearest(artillery)
  71.         archer = friend.findNearest(archers)
  72.         soldier = friend.findNearest(soldiers)
  73.         if friend.type == "arrow-tower":
  74.             targets = [archer, enemyArtillery, tower, soldier, enemyHero]
  75.             for target in targets:
  76.                 if not target: continue
  77.                 if target.distanceTo(friend) < 30:
  78.                     self.command(friend, "attack", target)
  79.                     break
  80.             continue
  81.         if friend.type == "artillery":
  82.             targets = [enemyArtillery, tower, enemyHero, archer, soldier]
  83.             for target in targets:
  84.                 if not target: continue
  85.                 if friend.distanceTo(target) < 15: continue
  86.                 self.command(friend, "attack", target)
  87.                 break
  88.             continue
  89.         # Archer logic
  90.         commanded = False
  91.         targets = [archer, enemyArtillery, tower]
  92.         for target in targets:
  93.             if not target: continue
  94.             if target.distanceTo(friend) < 30:
  95.                 self.command(friend, "attack", target)
  96.                 commanded = True
  97.                 break
  98.         if commanded: continue
  99.         for missile in missiles:
  100.             d = friend.distanceTo(missile.targetPos)
  101.             if missile.type is 'boulder' and d < 15 or missile.type is 'shell' and d < 20:
  102.                 flee = boundFlee(Vector.add(friend.pos, Vector.multiply(Vector.normalize(Vector.subtract(friend.pos, missile.targetPos)), 20)))
  103.                 if friend.distanceTo(flee) > 4:
  104.                     self.command(friend, "move", flee)
  105.                     commanded = True
  106.                     break
  107.         for meleeTarget in [soldier, enemyHero, tower]:
  108.             if not meleeTarget: continue
  109.             if self.now() > 120: continue
  110.             d = meleeTarget.distanceTo(friend)
  111.             if ((meleeTarget.type is 'goliath' and d < 15) or (meleeTarget.type is 'soldier' and d < 12) or (meleeTarget.type is 'arrow-tower' and d < 35)):
  112.                 flee = boundFlee(Vector.add(friend.pos, Vector.multiply(Vector.normalize(Vector.subtract(friend.pos, meleeTarget.pos)), 40)))
  113.                 if friend.distanceTo(flee) > 4:
  114.                     self.command(friend, "move", flee)
  115.                     commanded = True
  116.                     break
  117.                 else:
  118.                     d = 10
  119.             if d < 15:
  120.                 self.command(friend, "attack", meleeTarget)
  121.                 commanded = True
  122.                 break
  123.         if commanded: continue
  124.         if enemyArtillery and friend.distanceTo(enemyArtillery) < 40:
  125.             self.command(friend, "attack", enemyArtillery)
  126.             continue
  127.        
  128.         point = points[i % len(points)]
  129.         if point.name is 'farCorner':
  130.             point = pointsMap['center']
  131.         elif point.team is self.team and friend.distanceTo(point.pos) > 10:
  132.             point = pointsMap['center']
  133.         fighting = self.now() > 120 or self.health < 2000
  134.         if not fighting:
  135.             self.command(friend, "defend", point.pos)
  136.         else:
  137.             self.command(friend, "attack", friend.findNearest(enemies))
  138.            
  139. def boundFlee(flee):
  140.     flee.x = Math.min(Math.max(flee.x, 6), 114)
  141.     flee.y = Math.min(Math.max(flee.y, 6), 94)
  142.     if flee.x < 30 and flee.y > 74:
  143.         flee.x = 30
  144.         flee.y = 74
  145.     if flee.x > 90 and flee.y < 26:
  146.         flee.x = 90
  147.         flee.y = 26
  148.     return flee    
  149.            
  150. def controlHero():
  151.     enemies = self.findEnemies()
  152.     nearestEnemy = self.findNearest(enemies)
  153.     if not nearestEnemy: return
  154.     tower = self.findNearest(self.findByType("arrow-tower", enemies))
  155.     rangedAttacker = self.findNearest(self.findByType("archer", enemies))
  156.     if not rangedAttacker or self.distanceTo(rangedAttacker) > self.throwRange:
  157.         rangedAttacker = self.findNearest(self.findByType("artillery", enemies))
  158.     if not rangedAttacker or self.distanceTo(rangedAttacker) > self.throwRange:
  159.         rangedAttacker = tower
  160.     if rangedAttacker and self.distanceTo(rangedAttacker) < 25 and self.isReady("throw") and rangedAttacker.health >= 30:
  161.         self.throw(rangedAttacker)
  162.     elif tower and self.distanceTo(tower) < 30 and tower.distanceTo(centerPos) < 30:
  163.         self.attack(tower)
  164.     elif self.isReady("hurl") and nearestEnemy.type in ['goliath', 'ice-yak'] and self.distanceTo(nearestEnemy) < 8.00000000:
  165.         if nearestEnemy.distanceTo(pointsMap.farCorner.pos) < nearestEnemy.distanceTo(pointsMap.nearCorner.pos):
  166.             self.hurl(nearestEnemy, pointsMap.farCorner.pos)
  167.         else:
  168.             self.hurl(nearestEnemy, pointsMap.nearCorner.pos)
  169.     elif self.isReady("stomp") and self.distanceTo(nearestEnemy) < 6:
  170.         self.stomp(nearestEnemy)
  171.     elif self.health < 2000:
  172.         self.attack(self.findByType("goliath")[0] or nearestEnemy)
  173.     elif self.distanceTo(centerPos) < 1 and self.distanceTo(nearestEnemy, True) < 5:
  174.         self.attack(nearestEnemy)
  175.     else:
  176.         #self.move([map['nearB'].pos, map['nearA'].pos, map['center'].pos, map['farA'].pos][Math.floor(self.now() / 15) % 4])
  177.         self.move(centerPos)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×