Esempio n. 1
0
    def __init__(self, owner, owner_name):
        self.owner = owner
        self.owner_name = owner_name
        self.workforce = 1
        self.storage_capacity = 100
        self.buildings = [
            Building.Pipeline(),
            Building.Mine(),
            Building.Manor(),
            Building.Storage(),
        ]

        self.resources = {
            "gingerbread": 20,
            "cottoncandy": 20,
            "candy": 20,
            "chocolate": 20,
        }

        self.units = {}
        self.rallied_units = {}

        self.build_threads = []

        # all attack actions going on from this player
        self.attack_threads = []
        # all returning troop actions going on from this player
        self.return_threads = []
        # a list of messages that will be send to you every fast update
        self.messages = []
        self.protection = True
Esempio n. 2
0
    def test_buildable(self, building, built, pos):

        if building == "LumberYard":
            if built:
                Build = Building.LumberYard(self, self.lumberyard_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_img,
                                                   "LumberYard")

        elif building == "House":
            if built:
                Build = Building.House(self, self.house_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_house_img,
                                                   "House")

        elif building == "Dock":
            if built:
                Build = Building.Dock(self, self.dock_img)
            else:
                Build = Building.UnderConstruction(self, self.ucw_img, "Dock")

        elif building == "Manor":
            if built:
                Build = Building.Manor(self, self.manor_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_img, "Manor")

        buildable = 1
        land = 0
        water = 0

        Twidth, Theight = Build.image.get_size()
        for i in range(Twidth >> 5):
            for j in range(Theight >> 5):
                try:
                    if built:
                        test_tile = self.get_tile(
                            vector2.Vector2((pos.x - 32) + (i << 5),
                                            (pos.y - 32) + (j << 5)))
                        #print "A", test_tile, test_tile.location
                    else:
                        test_tile = self.get_tile(
                            vector2.Vector2(
                                ((pos.x - 32) - self.background_pos.x) +
                                (i << 5),
                                ((pos.y - 32) - self.background_pos.y) +
                                (j >> 5)))
                        #print "B", test_tile, test_tile.location

                    if test_tile.buildable != 1 and building != "Dock":
                        buildable = 0
                        return 0
                    elif building == "Dock":
                        if test_tile.buildable_w:
                            water += 1
                        elif test_tile.buildable:
                            land += 1
                except IndexError:
                    print 'IndexError'
                    return 0

        if building == "Dock" and not built:
            if water >= 1 and land <= 2 and land > 0:
                #print ('buildable', water, land)
                buildable = 1
                return 1, Build
            else:
                #print ('not buildable', water, land)
                buildable = 0
                return 0

        return 1, Build