Пример #1
0
    def populate(self):
        """adds all the people and make sure they don't go all ape shit
        """
        FARMER_COUNT = 4
        VILLAGER_COUNT = 5
        BUILDER_COUNT = 1

        lumber1 = Building.LumberYard(self, self.lumberyard_img)
        lumber1.location = vector2.Vector2(self.w / 2, self.h / 2)
        lumber1.tile_x, lumber1.tile_y = 4, 4
        self.add_entity(lumber1)

        for Villager_no in xrange(VILLAGER_COUNT):
            """Adds all Wood Cutters
            """
            villager = Lumberjack.Lumberjack(self, self.lumberjack_img)
            villager.location = lumber1.location.copy()
            villager.LastLumberYard = lumber1
            villager.brain.set_state("Searching")
            self.add_entity(villager)
            self.population += 1

        for Building_no in xrange(BUILDER_COUNT):
            builder = Builder.Builder(self, self.builder_img, lumber1)
            builder.location = lumber1.location.copy()
            builder.brain.set_state("Idle")
            self.add_entity(builder)
            self.population += 1

        for FARMER in xrange(FARMER_COUNT):
            """Adds all the farmers
            """
            farmer = Farmer.Farmer(self, self.farmer_img)
            farmer.location = vector2.Vector2(20, 20)
            farmer.brain.set_state("Planting")
            self.add_entity(farmer)
            self.population += 1
Пример #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