Esempio n. 1
0
	def check_build_line(cls, session, point1, point2, rotation=45, ship=None):

		# Pathfinding currently only supports buildingsize 1x1, so don't use it in this case
		if cls.size != (1, 1):
			return [ cls.check_build(session, point2, rotation=rotation, ship=ship) ]

		# use pathfinding to get a path, then try to build along it
		island = session.world.get_island(point1)
		if island is None:
			return []

		path = StaticPather.get_direct_path(island, point1, point2)
		if path is None: # can't find a path between these points
			return [] # TODO: maybe implement alternative strategy

		possible_builds = []

		for i in path:
			action = ''
			for action_char, offset in \
			    sorted(BUILDINGS.ACTION.action_offset_dict.iteritems()): # order is important here
				if (offset[0]+i[0], offset[1]+i[1]) in path:
					action += action_char
			if action == '':
				action = 'ac' # default

			build = cls.check_build(session, Point(*i))
			build.action = action
			possible_builds.append(build)

		return possible_builds
    def check_build_line(cls, session, point1, point2, rotation=45, ship=None):

        # Pathfinding currently only supports buildingsize 1x1, so don't use it in this case
        if cls.size != (1, 1):
            return [
                cls.check_build(session, point2, rotation=rotation, ship=ship)
            ]

        # use pathfinding to get a path, then try to build along it
        island = session.world.get_island(point1)
        if island is None:
            return []

        path = StaticPather.get_direct_path(island, point1, point2)
        if path is None:  # can't find a path between these points
            return []  # TODO: maybe implement alternative strategy

        possible_builds = []

        for i in path:
            action = ''
            for action_char, offset in \
                sorted(BUILDINGS.ACTION.action_offset_dict.iteritems()): # order is important here
                if (offset[0] + i[0], offset[1] + i[1]) in path:
                    action += action_char
            if action == '':
                action = 'ac'  # default

            build = cls.check_build(session, Point(*i))
            build.action = action
            possible_builds.append(build)

        return possible_builds
	def _check_market_place_in_range(self):
		"""Notifies the user via a message in case there is no market place in range"""
		for building in self.get_buildings_in_range():
			if building.id == BUILDINGS.MARKET_PLACE_CLASS:
				if StaticPather.get_path_on_roads(self.island, self, building) is not None:
					# a market place is in range
					return
		# no market place found
		self.session.ingame_gui.message_widget.add(self.position.origin.x, self.position.origin.y, \
		                                           'NO_MARKET_PLACE_IN_RANGE')
Esempio n. 4
0
	def _check_market_place_in_range(self):
		"""Notifies the user via a message in case there is no market place in range"""
		for building in self.get_buildings_in_range():
			if building.id == BUILDINGS.MARKET_PLACE_CLASS:
				if StaticPather.get_path_on_roads(self.island, self, building) is not None:
					# a market place is in range
					return
		# no market place found
		self.session.ingame_gui.message_widget.add(self.position.origin.x, self.position.origin.y, \
		                                           'NO_MARKET_PLACE_IN_RANGE')
Esempio n. 5
0
	def _check_main_square_in_range(self):
		"""Notifies the user via a message in case there is no main square in range"""
		for building in self.get_buildings_in_range():
			if building.id == BUILDINGS.MAIN_SQUARE_CLASS:
				if StaticPather.get_path_on_roads(self.island, self, building) is not None:
					# a main square is in range
					return
		# no main square found
		# check_duplicate: only trigger once for different settlers of a neighborhood
		self.session.ingame_gui.message_widget.add(self.position.origin.x, self.position.origin.y, \
		                                           'NO_MAIN_SQUARE_IN_RANGE', check_duplicate=True)
Esempio n. 6
0
def _building_connected_to_any_of(session, building_class, *classes):
	"""Returns the exact amount of buildings of type building_class that are
	connected to any building of a class in classes. Counts all settlements."""
	building_to_check = []
	check_connection = []
	for settlement in _get_player_settlements(session):
		building_to_check.extend(settlement.buildings_by_id[building_class])
		for b_class in classes:		
			for building in settlement.buildings_by_id[b_class]:
				check_connection.append(building)
	found_connected = 0
	for building in building_to_check:
		for check in check_connection:
			if StaticPather.get_path_on_roads(building.island, building, check):
				found_connected += 1
				break
	return found_connected
def _building_connected_to_any_of(session, building_class, *classes):
    """Returns the exact amount of buildings of type building_class that are
	connected to any building of a class in classes. Counts all settlements."""
    building_to_check = []
    check_connection = []
    for settlement in _get_player_settlements(session):
        for building in settlement.buildings:
            if building.id == building_class:
                building_to_check.append(building)
            else:
                for b_class in classes:
                    if building.id == b_class:
                        check_connection.append(building)
                        break
    found_connected = 0
    for building in building_to_check:
        for check in check_connection:
            if StaticPather.get_path_on_roads(building.island, building,
                                              check):
                found_connected += 1
                break
    return found_connected
def remove(s, p, before_ticks, after_ticks, tear_index):
	"""
	Place a couple of buildings and tear down one randomly, run a while afterwards.
	Called by test_removal with different parameters.
	"""
	settlement, island = settle(s)
	settlement.branch_office.inventory.adjust_limit(sys.maxint)

	# Plant trees
	for (x, y) in product(range(23, 38), repeat=2):
		if s.random.randint(0, 1) == 1:
			tree = Build(BUILDINGS.TREE_CLASS, x, y, island, settlement=settlement)(p)
			assert tree
			tree.finish_production_now()

	jack = Build(BUILDINGS.LUMBERJACK_CLASS, 25, 30, island, settlement=settlement)(p)
	assert jack
	jack = Build(BUILDINGS.LUMBERJACK_CLASS, 35, 30, island, settlement=settlement)(p)
	assert jack

	# Throw some fish into the water
	for x in (25, 30, 35):
		school = Build(BUILDINGS.FISH_DEPOSIT_CLASS, x, 18, s.world, ownerless=True)(None)
		assert school
		school.finish_production_now()

	fisherman = Build(BUILDINGS.FISHERMAN_CLASS, 25, 20, island, settlement=settlement)(p)
	assert fisherman
	fisherman = Build(BUILDINGS.FISHERMAN_CLASS, 35, 20, island, settlement=settlement)(p)
	assert fisherman

	# Some wild animals in the forest
	for (x_off, y_off) in product([-5, -4, 4, 5], repeat=2):
		x = 30 + x_off
		y = 30 + y_off
		animal = CreateUnit(island.worldid, UNITS.WILD_ANIMAL_CLASS, x, y)(None)
		assert animal
		animal.finish_production_now()

	hunter = Build(BUILDINGS.HUNTER_CLASS, 30, 35, island, settlement=settlement)(p)
	assert hunter

	# Build a farm
	assert Build(BUILDINGS.FARM_CLASS, 26, 33, island, settlement=settlement)(p)
	assert Build(BUILDINGS.PASTURE_CLASS, 22, 33, island, settlement=settlement)(p)
	assert Build(BUILDINGS.PASTURE_CLASS, 26, 37, island, settlement=settlement)(p)

	# Build roads
	for (start, dest) in [(Point(27, 30), Point(30, 23)), (Point(32, 23), Point(35, 30)),
						  (Point(25, 21), Point(30, 23)), (Point(32, 23), Point(35, 21)),
						  (Point(30, 35), Point(32, 25)), (Point(26, 33), Point(27, 30))]:
		path = StaticPather.get_direct_path(island, start, dest)
		assert path
		for (x, y) in path:
			a = Build(BUILDINGS.TRAIL_CLASS, x, y, island, settlement=settlement)(p)

	s.run(seconds=before_ticks)
	# Tear down a random building that is not a trail or tree.
	target = [b for b in settlement.buildings if b.id not in (BUILDINGS.TRAIL_CLASS, BUILDINGS.TREE_CLASS)][tear_index]
	Tear(target)(p)
	s.run(seconds=after_ticks)