def parseAction(self, sequence, enemyFrontCollection, myFront): """ :type sequence: tuple :type enemyFrontCollection: FrontCollection :type myFront: Front """ if myFront.getMeleeCount() == 0: return False if type(sequence) is tuple: for direction in sequence: if enemyFrontCollection.get(direction).getUnitsCount(): targetFront = enemyFrontCollection.get(direction) isClose = False if targetFront.getTarget() == myFront: isClose = targetFront.currentWaitToMove myFront.setTarget(targetFront, isClose) log.front('`%s` set target `%s`' % (targetFront.it, myFront.it)) return True return False else: for myDirection in sequence: # print(self.it, myDirection, sequence, sequence[myDirection]) if self.get(myDirection).getUnitsCount() == 0: return self.parseAction(sequence[myDirection], enemyFrontCollection, myFront)
def move(self): if self.currentWaitToMove: self.currentWaitToMove -= 1 log.front('`%s` move left %i' % (self.it, self.currentWaitToMove)) for group in self.groups: group.move()
def archersFire(self, target): if self.inDefence: bonus = self.location.getArcheryBonusDefender() else: bonus = self.location.getArcheryBonusAttacker() log.front('`%s` archery fire to `%s`' % ( self.it, target.it, )) for group in self.groups: group.archersFire(target, bonus)
def getNextTarget(self, frontName, enemyFrontCollection): """ :type frontName: string :type enemyFrontCollection: FrontCollection """ myFront = self.get(frontName) if myFront and myFront.getTarget() and myFront.getTarget( ).getUnitsCount(): log.front('`%s` has target `%s`' % (myFront.it, myFront.getTarget().it)) return else: if self.inDefence: sequence = self.location.getSequenceOfStrategicActionsDefender( ) else: sequence = self.location.getSequenceOfStrategicActionsAttacker( ) self.parseAction(sequence[frontName], enemyFrontCollection, myFront)
def importData(self, attacker, defender, location): """ :type attacker: battle.structure.front.FrontCollection :type defender: battle.structure.front.FrontCollection :type location: battle.places.abstract.AbstractPlace """ self.attacker = attacker self.defender = defender self.location = location self.attacker.setLocation(location) self.defender.setLocation(location) self.attacker.it = 'attacker' self.defender.it = 'defender' self.attacker.get(Front.TYPE_AVANGARD).it = 'attacker_avangard' self.attacker.get(Front.TYPE_LEFT_FLANG).it = 'attacker_left_flang' self.attacker.get(Front.TYPE_RIGHT_FLANG).it = 'attacker_right_flang' self.attacker.get(Front.TYPE_REAR).it = 'attacker_rear' self.defender.get(Front.TYPE_AVANGARD).it = 'defender_avangard' self.defender.get(Front.TYPE_LEFT_FLANG).it = 'defender_left_flang' self.defender.get(Front.TYPE_RIGHT_FLANG).it = 'defender_right_flang' self.defender.get(Front.TYPE_REAR).it = 'defender_rear' for direction in Front.TYPES: i = 1 for group in self.attacker.get(direction).getGroups(): group.it = self.attacker.get(direction).it + ('_group_%i' % i) y = 1 for unit in group.getUnits(): unit.it = group.it + '_unit_%s' % y y += 1 i += 1 i = 1 for group in self.defender.get(direction).getGroups(): group.it = self.defender.get(direction).it + ('_group_%i' % i) y = 1 for unit in group.getUnits(): unit.it = group.it + '_unit_%s' % y y += 1 i += 1 log.battle('INFORMATION ABOUT LOAD DATA') for direction in Front.TYPES: front = self.attacker.get(direction) log.front('%s front' % front.it) for group in front.getGroups(): log.group('%s group' % group.it) if group.general: log.unit('%s general with id %s' % (group.it, group.general.it)) for unit in group.getUnits(): log.unit('%s unit with id %s' % (unit.it, unit._id)) for direction in Front.TYPES: front = self.defender.get(direction) log.front('%s front' % front.it) for group in front.getGroups(): log.group('%s group' % group.it) if group.general: log.unit('%s general with id %s' % (group.it, group.general.it)) for unit in group.getUnits(): log.unit('%s unit with id %s' % (unit.it, unit._id))