Example #1
0
    def PlayCastleEvolution(self):

        # random.seed()

        self.__evolve_result["Evolutions"] = 0
        self.__evolve_result["Invictus"] = False
        self.__evolve_result["EternalDefeat"] = False

        # Setup window data
        self.__evolve_tkinter = Tk()
        self.__evolve_canvas = Canvas(self.__evolve_tkinter,
                                      height=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowHeight'),
                                      width=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowWidth'), bg="white")
        self.__evolve_canvas.pack()

        Battles.Utils.Message.Verbose = Battles.Utils.Message.VERBOSE_STATISTICS

        # Battles.Utils.Message.Log('The Battles for honor and glory have begun!!!! (castle evolution mode)',
        #                           Battles.Utils.Message.VERBOSE_EXTRA)

        # For the first evolution, we must draw the initial castle shape. We cannot do it here because the castle has not been yet initialized.
        # But we cannot do it later, because the window is invalidated only when main thread is released waiting the "after" calling (see below)
        # For that reason we  create here the castle and battlefield data
        self.__data.CastleData(self.__castle)
        self.__isCastleConstructed = True
        self.__battlefield = self.__data.BattleFieldData()
        self.__evolve_viewport = Viewport(Bounding(Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowWidth'),
                                                   Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowHeight')),
                                          self.__battlefield.GetBounding(), Point2D(x=0.0, y=0.0))
        self.__castle.Draw(self.__evolve_canvas, self.__evolve_viewport, moat=False, city=False, starfortress=False)
        self._resetData(removeCastle=False, removeBattleField=False, resetCounters=False)

        self.__evolve_tkinter.after(1000, self.__PlayCastleEvolution_Step)
        mainloop()
Example #2
0
 def __init__(self, army, number=0):
     Battalion.Battalion.__init__(self, army=army, number=number)
     self._action = Action.ActionFeatures(
         defense=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Defense'),
         attack=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Attack'),
         speed=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Speed'),
         reloadspeed=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Reload'),
         accuracy=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Accuracy'),
         distance=Battles.Utils.Settings.SETTINGS.Get_F(
             'Army', 'Archers', 'Distance'),
         stationary=Battles.Utils.Settings.SETTINGS.Get_B(
             'Army', 'Archers', 'Stationary'),
         movementpriority=Battles.Utils.Settings.SETTINGS.Get_I(
             'Army', 'Archers', 'Accuracy'))
     self._bounding = Bounding(
         Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Archers',
                                               'Bounding/Length'),
         Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Archers',
                                               'Bounding/Width'),
         Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Archers',
                                               'Bounding/Height'))
     self._label = "Archers_" + str(Archers.archersCounter)
     Archers.archersCounter += 1
     blackboard = b3.Blackboard()
     archerBlackboards[self._label] = blackboard
Example #3
0
    def DrawCastleShape(self, canvas=None, city=False, starfortress=False, resetData=True):

        # Draws the castle and city shape. If canvas is none, creates a new tkinter and canvas and executes a mainloop to show the window permanently

        # Setup window data
        if not canvas:
            loop = True
            tkr = Tk()
            canvas = Canvas(tkr, height=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowHeight'),
                            width=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowWidth'), bg="white")
            canvas.pack()
        else:
            loop = False

        # For the first evolution, we must draw the initial castle shape. We cannot do it here because the castle has not been yet initialized.
        # But we cannot do it later, because the window is invalidated only when main thread is released waiting the "after" calling (see below)
        # For that reason we  create here the castle and battlefield data
        self.__data.CastleData(self.__castle)
        self.__isCastleConstructed = True
        self.__battlefield = self.__data.BattleFieldData()
        viewport = Viewport(Bounding(Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowWidth'),
                                     Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowHeight')),
                            self.__battlefield.GetBounding(), Point2D(x=0.0, y=0.0))
        self.__castle.Draw(canvas, viewport, moat=False, city=city, starfortress=starfortress)

        if resetData:
            self._resetData(removeCastle=False, removeBattleField=False, resetCounters=False)

        if loop:
            mainloop()
Example #4
0
 def __init__(self, army, number = 0):
     Battalion.Battalion.__init__(self, army = army, number = number)
     self._action = Action.ActionFeatures(defense = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'Defense'), 
                                          attack = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'Attack'), 
                                          speed = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'Speed'), 
                                          reloadspeed = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'Reload'), 
                                          accuracy = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'Accuracy'), 
                                          distance = Battles.Utils.Settings.SETTINGS.Get_F('Army', 'SiegeTowers', 'Distance'), 
                                          stationary = Battles.Utils.Settings.SETTINGS.Get_B('Army', 'SiegeTowers', 'Stationary'),
                                          movementpriority = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'SiegeTowers', 'MovementPriority'))
     self._bounding = Bounding(Battles.Utils.Settings.SETTINGS.Get_F('Army', 'SiegeTowers', 'Bounding/Length'), 
                               Battles.Utils.Settings.SETTINGS.Get_F('Army', 'SiegeTowers', 'Bounding/Width'), 
                               Battles.Utils.Settings.SETTINGS.Get_F('Army', 'SiegeTowers', 'Bounding/Height'))
     self._label = "SiegeTowers_" + str(SiegeTowers.siegetowersCounter)
     SiegeTowers.siegetowersCounter += 1
     #print 'SiegeTowers ->', SiegeTowers.siegetowersCounter
     
     self._targetWall = None
     self._path = []
     self._status = SiegeTowers.CONSTRUCTING
     self.__army = None  
     self._moatCells = []
     self._turtle = None
     self._nLevels = 0
     
     self._constructionStatus = 0
     
     self._coverMoatHeight = 0
     
     self._nArchersPerLevel = (self._bounding.length * self._bounding.width) / (Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Archers', 'Bounding/Length') * Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Archers', 'Bounding/Width'))
     blackboard = b3.Blackboard()
     siegeTowerBlackboards[self._label] = blackboard
Example #5
0
    def BattleFieldData(self):
        battle = Battlefield.BattleField(bound=Bounding(500.0, 500.0),
                                         cellsize=10.0)
        trenches = [[[9, 24], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29],
                     [10, 29], [10, 30], [10, 31]]]
        battle.SetTrenchesPositions(trenches)

        return battle
Example #6
0
    def GetBoundingHeightView(self):

        # Returns the wall bounding for height view (width will be the height)
        l = self.GetLength()
        if l < self._height:
            d = self._height
        else:
            d = l

        # Apply offsets
        d += d * 0.1

        # Squared viewports avoid problems....
        return Bounding(length=d, width=d)
Example #7
0
    def BattleFieldData(self):
        battle = Battlefield.BattleField(bound=Bounding(500.0, 500.0),
                                         cellsize=10.0)
        trenches = [[[11, 29], [11, 30], [11, 31], [11, 32], [11, 33],
                     [11, 34], [12, 34], [12, 35], [12, 36]],
                    [[20, 7], [21, 7], [22, 7], [23, 7], [20, 8], [21, 8],
                     [22, 8], [23, 8]], [[8, 8], [8, 9]],
                    [[35, 30], [35, 31], [36, 30], [37, 30], [37, 33],
                     [35, 34], [35, 35], [37, 31]],
                    [[30, 37], [29, 38], [28, 39], [27, 40], [26, 40],
                     [25, 40], [24, 40]]]
        battle.SetTrenchesPositions(trenches)

        return battle
Example #8
0
    def __init__(self, battlefield, castle, defenders, attackers, showBoard=True, verbose=True):
        self.__battleField = battlefield
        self.__castle = castle
        self.__defenders = defenders
        self.__attackers = attackers

        self.__speed = Battles.Utils.Settings.SETTINGS.Get_I('Game', 'speed')

        self.__showBoard = showBoard

        self.__bypassedViewData = False
        self.__endControl = None

        if self.__showBoard:
            self.__masterTK = Tk()
            self.__canvas = Canvas(self.__masterTK,
                                   height=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowHeight'),
                                   width=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'WindowWidth'), bg="white")
            self.__canvas.pack()

            self.__viewport = Viewport(Bounding(Battles.Utils.Settings.SETTINGS.Get_I('Game', 'ViewportWidth'),
                                                Battles.Utils.Settings.SETTINGS.Get_I('Game', 'ViewportHeight')),
                                       self.__battleField.GetBounding(), Point2D(x=0.0, y=0.0))

            self.__battleField.Draw(self.__canvas, self.__viewport,
                                    showgrid=Battles.Utils.Settings.SETTINGS.Get_B(category='Game', tag='ShowGrid'))
            self.__castle.Draw(self.__canvas, self.__viewport, moat=True, city=True, starfortress=False)
            self.__attackers.Draw(self.__canvas, self.__viewport)
            self.__defenders.Draw(self.__canvas, self.__viewport)

            self.__shoots = []
            self.__heightViews = []

            self.__canvas.bind("<1>", lambda event: self.__canvas.focus_set())
            self.__canvas.bind("<Key>", self.KeyPressed)

        else:
            self.__masterTK = None
            self.__canvas = None
            self.__viewport = None
            self.__shoots = None
            self.__heightViews = None

        self.__stepStatus = self.__STEP_INIT
        self.__roundsCounter = 0
        self.__resultStatistics = None
Example #9
0
 def __init__(self, army, number = 0):
     Battalion.Battalion.__init__(self, army = army, number = number)
     self._action = Action.ActionFeatures( defense = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'Defense'), 
                                           attack = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'Attack'), 
                                           speed = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'Defense'), 
                                           reloadspeed = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'Reload'), 
                                           accuracy = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'Accuracy'), 
                                           distance = Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'Distance'),
                                           climbspeed = Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'ClimbSpeed'),
                                           stationary = Battles.Utils.Settings.SETTINGS.Get_B('Army', 'Infantry', 'Stationary'),
                                           movementpriority = Battles.Utils.Settings.SETTINGS.Get_I('Army', 'Infantry', 'MovementPriority'))
     self._bounding = Bounding( Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'Bounding/Length'), 
                                Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'Bounding/Width'), 
                                Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'Bounding/Height'))       
     self._label = "Infantry_" + str(Infantry.infantryCounter)
     Infantry.infantryCounter += 1
     #print 'Infantry ->', Infantry.infantryCounter,
       
     self._action.SetRubbleClimgingSpeed(Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Infantry', 'RubbleClimbSpeed'))  
     blackboard = b3.Blackboard()
     infantryBlackboards[self._label] = blackboard
Example #10
0
    def __init__(self, construction, enemyarmy):
        self.__construction = construction

        self.__view = Toplevel()
        self.__canvas = Canvas(self.__view, height=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'HeightViewHeight'),
                               width=Battles.Utils.Settings.SETTINGS.Get_I('Game', 'HeightViewWidth'), bg="white")
        self.__canvas.pack()
        self.__view.title(construction.GetLabel())

        self.__enemyarmy = enemyarmy

        # Creates the viewport
        cb = self.__construction.GetBoundingHeightView()
        self.__viewport = Viewport(viewSize=Bounding(Battles.Utils.Settings.SETTINGS.Get_I('Game', 'HeightViewWidth'),
                                                     Battles.Utils.Settings.SETTINGS.Get_I('Game', 'HeightViewHeight')),
                                   worldSize=cb)
        # Center view (approx)
        center = Point2D(cb.length * 0.05, cb.width * 0.1)
        self.__viewport.SetOffset(center)

        self.__construction.DrawHeightView(self.__enemyarmy, self.__canvas, self.__viewport)
Example #11
0
    def __init__(self, army, number=0):
        Battalion.Battalion.__init__(self, army=army, number=number)
        self._action = Action.ActionFeatures(
            defense=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'Defense'),
            attack=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'Attack'),
            speed=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'Speed'),
            reloadspeed=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'Reload'),
            accuracy=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'Accuracy'),
            distance=Battles.Utils.Settings.SETTINGS.Get_F(
                'Army', 'Throwers', 'Distance'),
            stationary=Battles.Utils.Settings.SETTINGS.Get_B(
                'Army', 'Throwers', 'Stationary'),
            movementpriority=Battles.Utils.Settings.SETTINGS.Get_I(
                'Army', 'Throwers', 'MovementPriority'))
        self._bounding = Bounding(
            Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Throwers',
                                                  'Bounding/Length'),
            Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Throwers',
                                                  'Bounding/Width'),
            Battles.Utils.Settings.SETTINGS.Get_F('Army', 'Throwers',
                                                  'Bounding/Height'))
        self._label = "Throwers_" + str(Throwers.throwersCounter)
        Throwers.throwersCounter += 1
        # print 'Throwers ->', Throwers.throwersCounter

        self._action.SetInitialReload(False)

        self._stair = None

        self._dissolvedBattalions = []
        blackboard = b3.Blackboard()
        throwerBlackboards[self._label] = blackboard
Example #12
0
    def BattleFieldData(self):
        # # Log('################################################################# ', VERBOSE_RESULT)
        # # Log('#  Creating Battlefield Data                                    # ', VERBOSE_RESULT)
        # # Log('################################################################# ', VERBOSE_RESULT)

        b = self.__xml.Get_F(category='Battlefield', tag='Bounding')
        battle = Battlefield.BattleField(bound=Bounding(b, b),
                                         cellsize=self.__xml.Get_F(category='Battlefield', tag='CellSize'))

        if self.__xml.HasTag(category='Battlefield', tag='Trenches'):
            # Log('#  Creating Battlefield Trenches', VERBOSE_RESULT)
            trenches = self.__xml.GetCollection(category='Battlefield', tag='Trenches', key='Set')
            if trenches != None:
                tlist = []
                for t in trenches:
                    tlist.append(self.__xml.Get_A(root=t))

                battle.SetTrenchesPositions(tlist)

        if self.__xml.HasTag(category='Battlefield', tag='Rivers'):
            ## Log('#  Creating Battlefield Rivers', VERBOSE_RESULT)
            rivers = self.__xml.GetCollection(category='Battlefield', tag='Rivers', key='Trace')
            if rivers != None:
                for r in rivers:
                    width = self.__xml.Get_F(category='Width', root=r)
                    poly = self.__xml.GetCollection(category='Polyline', key='Vertex', root=r)
                    if poly != None:
                        plist = []
                        for p in poly:
                            v = self.__xml.Get_A(root=p)
                            plist.append(Point2D(v[0], v[1]))

                        river = River.River(width=width, polyline=plist)
                        battle.DeployRiver(river)

        return battle
Example #13
0
class Battalion:
    """ A generic army component class, such as  intantery, cavalry, ... This would never be used in battle, so it has dummy contents
    
    Class attr:
        bounding: Bounding box that has each one of the objects of current type: length, width and height.
    """
    
    bounding = Bounding( ARMYCOMPONENT_BOUNDING,  ARMYCOMPONENT_BOUNDING,  ARMYCOMPONENT_BOUNDING) 
    
    @staticmethod
    def GetNumberByCell(cellsize):
        # Returns the number of effective that fit in a square cell of given size
        if (cellsize < Battalion.bounding.length) or (cellsize < Battalion.bounding.width):
            return 0
        else:
            l = int(cellsize / Battalion.bounding.length)
            w = int(cellsize / Battalion.bounding.width)
            return l * w

    """ 
    Attributes:
        number: number of effective of current type
        freenumber: number of free effective of current type. Usefull when the army is placed. At the end of placement it should be 0
        action: Action definition (attack, defense....) See Battle.Action class to more info
         
        placement: Battalion placement management object
        isdead: True if current component is dead
        canvasobj : internal tkinter list of canvas objects used to draw the army component. Stored to allow refreshing their status
        army: Owner army
    """
    def __init__(self, army, number = 0):
        self._number = number             
        self._action = Action.ActionFeatures(defense = 0, attack = 0, speed = 0, reloadspeed = 0, accuracy = 0, distance = 0, stationary = False, movementpriority = 0)
          
        self._placement = Action.Placement(self)
        self._isDead = False
        self._canvasObjs = []
        self._label = "Battalion"
        self._army = army
       

#     def FitInCell(self, celllength, cellwidth):
#         # Returns true if current bounds fit in given cell size
#         if ((celllength < self._bounding.length) or (cellwidth < self._bounding.width)):
#             return False
#         else:
#             return True


    def GetCopy(self):
        # Returns a copy of itself
        factory = ArmyFactory()
        ret = factory.newBattalionNoCrop(army = self._army, kind = factory.GetArmyType(self))
        if ret == None:
            return None
       
        ret._number = self._number
        ret._bounding = Battalion.bounding
        ret._isDead = self._isDead
        ret._canvasObjs = []
        
        ret._action = self._action.GetCopy()
        ret._placement = self._placement.GetCopy(ret)
        
        return ret

         
    def GetLabel(self):
        return self._label

         
    def SetNumber(self, n):
        # Sets the initial number of effectives
        self._number = n
         
        
    def GetNumber(self):
        return self._number
        
        
    def GetBounding(self):
        return Battalion.bounding
    
    
    def GetBoundingQuad(self):
        # Return the bounding rectangle in world coordinates
        
        center = self.GetCenterPosition()
        minP = Point2D(center.x - (Battalion.bounding.length / 2.0), center.y - (Battalion.bounding.width / 2.0))
        maxP = Point2D(center.x + (Battalion.bounding.length / 2.0), center.y + (Battalion.bounding.width / 2.0))
        # Note that this is true since the battlefield is orthonormal
        
        return BoundingQuad(minPoint = minP, maxPoint = maxP)
        
        
    def GetSoldierBoxVolume(self):
        # Returns the volume of one soldier/unit in battalion
        return Battalion.bounding.GetVolume()    
        
       
    def SetDefense(self, d): 
        self._action.SetDefense(d)  

        
    def SetExtraDefense(self, v):
        # Increases the action defense value
        self._action.SetExtraDefense(v)    

         
    def AssignToCell(self, groundcell):
        # Updates cell
        self._placement.SetBattlefieldCell(groundcell)
        groundcell.SetBattalion(self)       

        # From battlefield there are not restrictions on attack vector and angle
        self._action.SetAttackVector(Vector2D(), None)
        
        
    def AssignToConstruction(self, construction, defendingline):
        # Updates position
        self._placement.SetDefendingLine(construction, defendingline)
        
        # Updates battalion data from construction features
        construction.SetBattalionConstructionData(self, defendingline)
   
   
    def GetCommand(self):
        return self._action.GetCommand()
    
    def SetCommand(self, command, target = None, commander = None):
        #print "SetCommand:", self._label, " ->", command
        self._action.SetCommand(command, target, commander)
        
    def SetAttackVector(self, direction, angle):
        self._action.SetAttackVector(direction, angle)    
        
        
    def Attack(self, against, castle, shoots):
        pass   
        
    def Defend(self, against, defenders, battlefield, shoots, castle):
        pass   
        
    def GetDefenseVal(self):    
        return self._action.GetDefense()
    
    def GetClimbingSpeed(self):
        return self._action.GetClimbingSpeed()
    
    def GetRubbleClimbingSpeed(self):
        return self._action.GetRubbleClimbingSpeed()
    
    
    def Kill(self, number, respawn = False):
        # Kills elements in current battalion
        # If given number is -1, kills the whole battalion
        # Respawn is only allowed for defender archers
        
        if number == -1:
            number = self.GetNumber()
        
        #self._number -= number;
        self.SetNumber(self.GetNumber() - number)
        
        if self._number <= 0:
            self._isDead = True
            self._number = 0
            Log('Battalion of %s exterminated' % (self.GetLabel()))
            
        self._placement.Kill(self._number)
            

    def GetCenterPosition(self):  
        return self._placement.GetCenterPosition()

        
    def GetRandomPosition(self):
        return self._placement.GetRandomPosition()    
        

    def GetBattlefieldCell(self):
        # Returns the battlefield cell if it is deployed on it, otherwise return None
        return self._placement.GetBattlefieldCell()

        
    def DistanceSort(self, frompos):
        # Return the distance from current position to given point
        # This is a convenience method created to sort lists of batttalions by distance
        # WARNING: Due this method is used for sorting purposes, the returned distance is squared, avoiding the overload of sqrt or hypot functions
        
        center = self._placement.GetCenterPosition()
        dist = ((frompos.x - center.x)**2) + ((frompos.y - center.y)**2) + ((frompos.z - center.z)**2) 
        return dist
        
        
        
    def Draw(self, canvas, viewport):
        if self._isDead:
            return
        # This color selection is ugly. But I don't want to place too much code just for color selection for tkinter. This is not the goal 
        factory = ArmyFactory()
        fillcolor = "red"
        if factory.IsArcher(self):
            fillcolor = "Light Coral"
        if factory.IsInfantry(self):
            fillcolor = "red"
        if factory.IsCannon(self):
            fillcolor = "Dark Orange"
        if factory.IsSiegeTower(self):
            fillcolor = "Pale Violet Red"
        if Battles.Utils.Settings.SETTINGS.Get_B('Army', 'ShowOutline'):
            outline = "gray"
        else:
            outline = fillcolor

        if self._placement.IsClimbing():
            # Draw the soldier attached to the climbing wall
            s = self._placement.GetCenterPosition()                
            p = s.Copy()
            p.x = s.x - (Battalion.bounding.length / 2.0)
            p.y = s.y - (Battalion.bounding.width / 2.0)
            pv = viewport.W2V(p)
            p.x += Battalion.bounding.length
            p.y += Battalion.bounding.width
            pv2 = viewport.W2V(p)
            self._canvasObjs.append(canvas.create_rectangle(pv.x, pv.y, pv2.x, pv2.y, fill=fillcolor, width=1, outline=outline))
        elif self._placement.IsInBattlefield():
            # Draw the battalion on the battlefield

            # Get cell center
            center = self._placement.GetCenterPosition()
            cs = self._placement.GetCellSize()
            # Draw each troop element
            cols = int(cs / Battalion.bounding.length)
            rows = int(cs / Battalion.bounding.width)
           
            counter = 0
            i = 0
            p = Point2D()
            p.y = center.y- cs/2
            while (i < rows) and (counter < self._number):
                j = 0
                p.x = center.x - cs/2
                while (j < cols) and (counter < self._number):
                    pv = viewport.W2V(p)
                    pv2 = viewport.W2V(Point2D(p.x + Battalion.bounding.length, p.y + Battalion.bounding.width))
                    self._canvasObjs.append(canvas.create_rectangle(pv.x, pv.y, pv2.x, pv2.y, fill=fillcolor, width=1, outline=outline))
                    p.x = p.x + Battalion.bounding.length
                    j += 1
                    counter += 1
                p.y = p.y + Battalion.bounding.width
                i += 1

            if self._action.GetCommand().IsCoverMoat():
                halfsize = cs / 2.0
                p1 = Point2D(center.x - halfsize, center.y - halfsize)
                p3 = Point2D(center.x + halfsize, center.y + halfsize)
                p2 = Point2D(p3.x, p1.y)
                p4 = Point2D(p1.x, p3.y)
                pv1 = viewport.W2V(p1)
                pv2 = viewport.W2V(p2)
                pv3 = viewport.W2V(p3)
                pv4 = viewport.W2V(p4)
                self._canvasObjs.append(canvas.create_line(pv1.x, pv1.y, pv3.x, pv3.y, fill="black"))
                self._canvasObjs.append(canvas.create_line(pv4.x, pv4.y, pv2.x, pv2.y, fill="black"))
    
            if Battles.Utils.Settings.SETTINGS.Get_B('Army', 'ShowLabels'):
                # Text the kind of battalion
                cv = viewport.W2V(Point2D(center.x, center.y))
                self._canvasObjs.append(canvas.create_text(cv.x, cv.y, text=self.GetLabel(), fill="gray"))
        
        elif self._placement.IsInDefendingLine():
            # Draw the battalion on the construction
            # There are a lot of different construction types. So we delegate the drawing to these kind of objects
            dl = self._placement.GetDefendingLine()
            dc = self._placement.GetDefendingConstruction()
            dc.DrawBattalion(dl, self, canvas, viewport, self._canvasObjs)
      
       
    def RedrawAttacked(self, canvas, viewport):
        # Redraws the army componet after an attack
        
        if len(self._canvasObjs) > 0:
            for c in self._canvasObjs:
                canvas.delete(c)
 
        self.Draw(canvas, viewport)
        
        
    def IsDefeated(self):
        if self._isDead:
            return True
        else:
            return False

      
    def Move(self, castle, selfarmy, againsarmy, battlefield, movedList):
        pass
         
    
    def SetMovementPriority(self, p):
        self._action.SetMovementPriority(p)
        
        
    
    def IsInBattleField(self):
        return self._placement.IsInBattlefield()
Example #14
0
def getBattalionDimensions(kind):
    return Bounding(settings.SETTINGS.Get_F('Army', 'Archers', 'Bounding/Length'), 
                    settings.SETTINGS.Get_F('Army', 'Archers', 'Bounding/Width'), 
                    settings.SETTINGS.Get_F('Army', 'Archers', 'Bounding/Height'))
Example #15
0
 def BattleFieldData(self):
     battle = Battlefield.BattleField(bound=Bounding(500.0, 500.0),
                                      cellsize=10.0)
     return battle
Example #16
0
 def BattleFieldData(self):
     # A simple and small battlefield
     battle = Battlefield.BattleField(bound=Bounding(100.0, 100.0),
                                      cellsize=10.0)
     return battle