Exemplo n.º 1
0
    def GetBoundingBox(self):
        bbox = Geometry.BoundingQuad()

        p = self.center.Copy()
        p.Move(Geometry.Vector2D(-1, -1), self.__size / 2.0)
        bbox.InsertPoint(p)
        p = self.center.Copy()
        p.Move(Geometry.Vector2D(-1, 1), self.__size / 2.0)
        bbox.InsertPoint(p)
        p = self.center.Copy()
        p.Move(Geometry.Vector2D(1, -1), self.__size / 2.0)
        bbox.InsertPoint(p)
        p = self.center.Copy()
        p.Move(Geometry.Vector2D(1, 1), self.__size / 2.0)
        bbox.InsertPoint(p)

        return bbox
Exemplo n.º 2
0
    def Draw(self, dc, document, canvas):

        towerdata = document.GetDefaultSettings().castle.towers
        self.size = towerdata.squareSide / 2.0

        lastpen = dc.GetPen()
        dc.SetPen(wx.Pen(wx.Colour(100, 100, 100, wx.ALPHA_OPAQUE), 1))

        if (self.__towertype == self.TOWERTYPE_SQUARED):
            center = self.__center.Copy()
            center.Move(Geometry.Vector2D(-1, -1), towerdata.squareSide / 2.0)
            center = canvas.UserToScreenCoord(center.x, center.y)
            side = canvas.UserToScreenValue(
                towerdata.squareSide
            )  # NOTE: This sould be changed if window/viewport are not squared
            dc.DrawRectangle(center.x, center.y, side, side)

        if (self.__towertype == self.TOWERTYPE_ROUNDED):
            center = self.__center.Copy()
            center.Move(Geometry.Vector2D(-1, -1),
                        towerdata.circleRadius / 2.0)
            center = canvas.UserToScreenCoord(center.x, center.y)
            radius = canvas.UserToScreenValue(
                towerdata.circleRadius
            )  # NOTE: This sould be changed if window/viewport are not squared
            dc.DrawEllipse(center.x, center.y, radius * 2, radius * 2)

        if (self.__towertype == self.TOWERTYPE_RANDOM):
            lastfont = dc.GetFont()
            currfont = wx.Font(pointSize=25,
                               family=wx.FONTFAMILY_DEFAULT,
                               style=wx.FONTSTYLE_NORMAL,
                               weight=wx.FONTWEIGHT_BOLD)
            dc.SetFont(currfont)
            center = canvas.UserToScreenCoord(self.__center.x, self.__center.y)
            dc.DrawText("?", center.x, center.y)
            dc.SetFont(lastfont)

        dc.SetPen(lastpen)
Exemplo n.º 3
0
    def Draw(self, dc, document, canvas):

        citydata = document.GetDefaultSettings().city
        self.__size = citydata.housesSize

        lastpen = dc.GetPen()
        lastbrush = dc.GetBrush()
        dc.SetPen(wx.Pen(wx.Colour(141, 114, 71, wx.ALPHA_OPAQUE), 1))
        dc.SetBrush(wx.Brush(wx.Colour(234, 207, 160), wx.SOLID))

        p = self.center.Copy()
        p.Move(Geometry.Vector2D(-1, -1), citydata.housesSize / 2.0)

        p = canvas.UserToScreenCoord(p.x, p.y)
        size = canvas.UserToScreenValue(
            citydata.housesSize
        )  # NOTE: This sould be changed if window/viewport are not squared. A polygon should be calculated instead
        dc.DrawRectangle(p.x, p.y, size, size)

        dc.SetBrush(lastbrush)
        dc.SetPen(lastpen)
Exemplo n.º 4
0
    def ImportXML(self, root, document):

        main = root.find("BattleEvents")
        if (not main):
            return

        for battlexml in main:
            if (battlexml.tag == "Battle"):
                battle = BE_BattleData()

                try:
                    battle.year = int(battlexml.find("Year").text)
                except:
                    print "ERROR: Battle year not specified in a battle of the  BattleEvents category"
                    continue

                try:
                    battle.nSimulations = int(
                        battlexml.find("Simulations").text)
                except:
                    print "WARNING: Wrong battle simulations number in a battle of the  BattleEvents category"

                try:
                    battle.repeatUntil = (
                        battlexml.find("RepeatUntilDefendersWin").text
                        in ['True', 'true', 'yes', 'YES', '1', 'Yes', 'TRUE'])

                except:
                    print "WARNING: RepeatUntilDefendersWin tag not found in a battle of the  BattleEvents category"

                # Defenders
                defendersxml = battlexml.find("Defenders")
                if (defendersxml != None):
                    try:
                        archersxml = defendersxml.find("Archers")
                        if (archersxml != None):
                            battle.defenders['Archers'] = int(archersxml.text)
                        else:
                            battle.defenders['Archers'] = 0
                        cannonsxml = defendersxml.find("Cannons")
                        if (cannonsxml != None):
                            battle.defenders['Cannons'] = int(cannonsxml.text)
                        else:
                            battle.defenders['Cannons'] = 0

                    except:
                        print "WARNING: Wrong defenders data in a battle of the BattleEvents category"
                else:
                    print "WARNING: None defenders has been specified in a battle of the BattleEvents category"

                # Attackers
                attackersxml = battlexml.find("Attackers")
                if (attackersxml != None):
                    # Flanks
                    for flankxml in attackersxml:
                        if (flankxml.tag == "Flank"):

                            flank = BE_Objects.BE_Flank()
                            flank.year = battle.year

                            try:

                                dist = flankxml.find("StandDistance")
                                if (dist != None):
                                    flank.standDistance = float(
                                        dist.text)  # Optional

                                # TODO: Place the arrow flank considering the standdistance

                                dirxml = ast.literal_eval(
                                    flankxml.find("Direction").text)
                                direction = Geometry.Vector2D(
                                    float(dirxml[0]), float(dirxml[1]))
                                direction.Normalize()

                                originxml = flankxml.find("origin")
                                if (originxml != None):
                                    origin = ast.literal_eval(originxml.text)
                                    flank.origin = Geometry.Point2D(
                                        float(origin[0]), float(origin[1]))
                                else:
                                    # Directional flank (no origin)
                                    # Place the arrow at the viewport edges
                                    viewsize = document.GetDefaultSettings(
                                    ).game.viewportSize
                                    origin = Geometry.Point2D(
                                        viewsize / 2.0, viewsize / 2.0)
                                    origin.Move(direction.Copy().Invert(),
                                                viewsize / 2.0)
                                    flank.origin = origin.Copy()

                                    # TODO : Improve this to work with standdistance

                                # Since arrow length is not used in the simulation, it could not be found in the incoming xml (except it is created by the editor, see ExportXML)
                                # If it is not present, use a default value
                                arrowlengthxml = flankxml.find(
                                    "BE_Editor_ArrowLength")
                                if (arrowlengthxml == None):
                                    arrowlength = 200.0
                                else:
                                    arrowlength = float(arrowlengthxml.text)

                                flank.target = flank.origin.Copy()
                                flank.target.Move(direction, arrowlength)

                            except:
                                print "WARNING: Wrong flank data of a battle in BattleEvents category"

                            # Flank battalions
                            battalionsxml = flankxml.find("Battalions")
                            if (battalionsxml != None):
                                for battalionxml in battalionsxml:

                                    try:
                                        type = battalionxml.find("Type").text
                                        number = int(
                                            battalionxml.find("Number").text)

                                        batsizexml = battalionxml.find(
                                            "BattalionSize")
                                        if (batsizexml != None):
                                            battalionsize = int(
                                                batsizexml.text)
                                        else:
                                            battalionsize = None

                                        groupsizexml = battalionxml.find(
                                            "GroupSize")
                                        if (groupsizexml != None):
                                            groupsize = int(groupsizexml.text)
                                        else:
                                            groupsize = None

                                        groupdistxml = battalionxml.find(
                                            "GroupDistance")
                                        if (groupdistxml != None):
                                            groupdist = int(groupdistxml.text)
                                        else:
                                            groupdist = None

                                        flank.battalions[type] = {
                                            'Number': number,
                                            'BattalionSize': battalionsize,
                                            'GroupSize': groupsize,
                                            'GroupDistance': groupdist
                                        }

                                    except:
                                        print "WARNING: Wrong battalion data in a flank of the BattleEvents category"

                            else:
                                print "WARNING: None battalion has found in a flank of the BattleEvents category"

                            battle.flanks.append(flank)
                            document.AddCanvasObject(flank)

                else:
                    print "WARNING: None attackers has been specified in a battla of the BattleEvents category"

                battle.SetColor()
                self.__battles[battle.year] = battle
Exemplo n.º 5
0
    def ImportXML(self, root, document):

        main = root.find("CityEvolutions")
        if (not main):
            return

        for groupxml in main:
            if (groupxml.tag == "Group"):
                try:
                    groupid = int(groupxml.find("ID").text)

                    evolutionsxml = groupxml.find("Evolutions")
                    for evxml in evolutionsxml:

                        cityevolution = BE_Objects.BE_CityEvolution()
                        cityevolution.groupID = groupid

                        arr = ast.literal_eval(evxml.find("TimeRange").text)
                        cityevolution.timeRange = [int(arr[0]), int(arr[1])]
                        cityevolution.housesPerYear = float(
                            evxml.find("HousesPerYear").text)

                        # Reconstruct the base segment and arrow
                        arrdir = ast.literal_eval(evxml.find("Direction").text)
                        direction = Geometry.Vector2D(float(arrdir[0]),
                                                      float(arrdir[1]))
                        direction.Normalize()
                        basexml = evxml.find("SegmentBase")
                        arrp1 = ast.literal_eval(basexml.find("P1").text)
                        arrp2 = ast.literal_eval(basexml.find("P2").text)
                        cityevolution.baseSegment.p1 = Geometry.Point2D(
                            float(arrp1[0]), float(arrp1[1]))
                        cityevolution.baseSegment.p2 = Geometry.Point2D(
                            float(arrp2[0]), float(arrp2[1]))

                        # Since arrow length is not used in the simulation, it could not be found in the incoming xml (except it is created by the editor, see ExportXML)
                        # If it is not present, use the base segment length as the default one

                        arrowlengthxml = evxml.find("BE_Editor_ArrowLength")
                        if (arrowlengthxml == None):
                            arrowlength = cityevolution.baseSegment.GetLength()
                        else:
                            arrowlength = float(arrowlengthxml.text)

                        mid = cityevolution.baseSegment.GetMidPoint()
                        mid.Move(direction, arrowlength)
                        cityevolution.arrow.p1 = cityevolution.baseSegment.GetMidPoint(
                        )
                        cityevolution.arrow.p2 = mid

                        document.AddCanvasObject(cityevolution)

                except:
                    print "WARNING: Wrong city evolution data in CityEvolutions category"

        # Parse the city expansion checkings
        cityexpandxml = root.find("CityExpansion")

        try:
            walldims = ast.literal_eval(
                cityexpandxml.find("WallDimensions").text)
            self.__wallsDimensions[0] = float(walldims[0])
            self.__wallsDimensions[1] = float(walldims[1])
        except:
            pass  # Optional

        try:
            self.__yearsBetweenExpansions = int(
                cityexpandxml.find("YearsBetweenExpansions").text)
        except:
            pass  # Optional

        if (cityexpandxml != None):
            for expxml in cityexpandxml:
                if (expxml.tag == "Expansion"):
                    try:
                        year = int(expxml.find("Year").text)
                        groupid = int(expxml.find("GroupID").text)
                        wxml = expxml.find("WallHeight")
                        if (wxml != None):  # Optional
                            wheight = float(wxml.text)
                        else:
                            wheight = None
                        txml = expxml.find("TowerHeight")
                        if (txml != None):  # Optional
                            theight = float(txml.text)
                        else:
                            theight = None

                        self.__expansions[str(groupid)] = {
                            'Year': year,
                            'WallsHeight': wheight,
                            'TowersHeight': theight
                        }

                    except:
                        print "WARNING: Wrong city expansion data in CityExpansions category"