Working on the first part of Summit’s Gate. Getting a very odd error: “Assigning to rvalue” and it isn’t giving me a line number or any other reasonable way to track it down. Anyone able to spot where I messed up?
def archerTarget(arch, range):
enemies = arch.findEnemies()
if len(enemies) < 1:
answer = None
elif len(enemies) < 2:
answer = enemies[0]
else:
answer = arch.findNearest(enemies)
dToEnemies = arch.distanceTo(answer)
for enemy in enemies:
if arch.distanceTo(enemy) < range:
if ((enemy.maxHealth > answer.maxHealth) and (enemy.health > 0)):
answer = enemy
dToEnemies = arch.distanceTo(answer)
elif ((enemy.maxHealth >= answer.maxHealth) and (enemy.health > 0) and arch.distanceTo(enemy) < dToEnemies):
answer = enemy
dToEnemies = arch.distanceTo(enemy)
return answer
while self.now() < 1:
self.move(Vector(61,42))
UpFirst = True
stepCounter = 0
loop:
#Soldiers' orders
troops = self.findByType("soldier", self.findFriends())
if len(troops) > 0:
for t in troops:
if UpFirst:
posA = Vector.add(t.pos, Vector(2, 2))
else:
posA = Vector.add(t.pos, Vector(2,-2))
if self.isPathClear(t.pos, posA):
self.command(t, "defend", posA)
#Archers' orders
troops = self.findByType("archer", self.findFriends())
if len(troops) > 0:
for archer in troops:
tarA = archerTarget(archer, 15)
if archer.distanceTo(tarA) < 20:
self.command(archer, "attack", tarA)
else:
if UpFirst:
posA = Vector.add(archer.pos, Vector(2,2))
else:
posA = Vector.add(archer.pos, Vector(2,-2))
if self.isPathClear(archer.pos, posA):
self.command(archer, "defend", posA)
#Paladins' orders
troops = self.findByType("paladin", self.findFriends())
if len(troops) > 0:
for pal in troops:
self.command(pal, "move", Vector.add(pal.pos, Vector(1,0)))
if pal.canCast("heal"):
allTroops = pal.findFriends()
healthFraction = 0.5
tarA = None
for trooper in allTroops:
if ((trooper.health/trooper.maxHealth < healthFraction) and (trooper.health > 5)):
tarA = trooper
healthFraction = trooper.health / trooper.maxHealth
if tarA:
self.command(pal, "cast", "heal", tarA)
if len(self.findEnemies()) > 0:
tarA = self.findNearest(self.findEnemies())
while ((len(self.findEnemies()) > 0) and (self.distanceTo(tarA) < self.attackRange) and (tarA.health < self.attackDamage)):
self.attack(tarA)
tarA = self.findNearest(self.findEnemies())
#Moving a soldier and character towards catapults
catapult = self.findByType("catapult", self.findEnemies())
if len(catapult)=2:
if catapult[0]:
allTroops = self.findByType("soldier", self.findFriends())
if len(allTroops) > 0:
troop = catapult[0].findNearest(allTroops)
self.command(troop, "attack", catapult[0])
if catapult[1]:
allTroops = self.findByType("soldier", self.findFriends())
if len(allTroops) > 0:
troop = catapult[1].findNearest(allTroops)
self.command(troop, "attack", catapult[1])
stepCounter = stepCounter + 1
tarA = self.findNearest(catapult)
if tarA:
if ((self.distanceTo(tarA) < self.attackRange + 4) or (self.pos.x > 80)):
self.attack(tarA)
elif UpFirst:
if catapult[0]:
tarA = catapult[0].pos
else:
tarA = None
if tarA:
self.move(tarA)
if stepCounter = 5:
UpFirst = False
stepCounter = 0
else:
if catapult[1]:
self.move(catapult[1].pos)
if stepCounter = 5:
UpFirst = True
stepCounter = 0
elif len(catapult)=1:
if (catapult[0] and (len(self.findByType("soldier", self.findFriends())) > 0)):
troop = catapult[0].findNearest(self.findByType("soldier", self.findFriends()))
self.command(troop, "attack", catapult[0])
stepCounter = stepCounter + 1
if catapult[0]:
self.attack(catapult[0])