Exemplo n.º 1
0
 def get(self, swLat, swLon, neLat, neLon):
     """Handles a post request to this page"""
     aEBounds = Bounds.createBoundsFromSimpleData(float(swLat), float(swLon), float(neLat), float(neLon))
     logging.error(aEBounds)
     # Check if one of the objects is on the map
     results = Road.getObjectInBounds(aEBounds)
     if len(results) == 0:
         self.loadRandomDataInBounds(aEBounds)
     
     # Find all of the drawable object within the bounds
     listOfObjects = []
     listOfObjects.extend(Road.getObjectInBounds(aEBounds))
     listOfObjects.extend(Portal.getObjectInBounds(aEBounds))
     listOfObjects.extend(Tower.getObjectInBounds(aEBounds))
     
     # Convert the list of objects into a response
     writeString = '<?xml version="1.0" encoding="UTF-8"?>'
     writeString += "<response>" 
     if listOfObjects is not None:
         for model in listOfObjects:
             if model:
                 writeString += model.toXML()
     writeString += "</response>" 
     
     logging.error(writeString )
     
     # Write the response back to the user
     self.response.out.write(writeString)
Exemplo n.º 2
0
    def is_room(self, start_position, area_bounds):
        found_floor = False
        current_position = Vector(start_position.x, start_position.y + 1)

        # Check vertical for the room bounds
        while (current_position.y <= area_bounds.y_max and not found_floor):
            if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]):
                found_floor = True
                current_position.y -= 1
            else:
                current_position.y += 1
        room_bounds_y = current_position.y
        next_position = room_bounds_y + 1

        if not found_floor or room_bounds_y == start_position.y:
            return False, next_position, None

        # Check horizontal for the room bounds
        found_floor = False
        current_position.x += 1

        while (current_position.x <= area_bounds.x_max and not found_floor):
            if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]):
                found_floor = True
                current_position.x -= 1
            else:
                current_position.x += 1

        room_bounds_x = current_position.x
        if not found_floor or room_bounds_x == start_position.x:
            return False, next_position, None

        # Check vertical with the bounds found for y
        for y in range(start_position.y, room_bounds_y + 1):
            current_position.y = y
            if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]):
                return False, next_position, None

        # Check horizontal with the bounds found for y
        current_position.y = start_position.y
        for x in range(start_position.x, room_bounds_x + 1):
            current_position.x = x
            if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]):
                return False, next_position, None

        if abs(start_position.x - room_bounds_x) == 1 or \
           abs(start_position.y - room_bounds_y) == 1:
            return False, next_position, None

        room_bounds = Bounds(start_position.x, start_position.y, room_bounds_x,
                             room_bounds_y)
        return True, next_position, room_bounds
Exemplo n.º 3
0
    def evaluate_dungeon(self, data):
        self.convert(data)

        results = list()

        bounds = Bounds(0, 0, DUNGEON_DIMENSION, DUNGEON_DIMENSION)

        # Evaluate bounds of tilemap are walls
        bounds_are_walls_result = self.evaluate_bounds_are_of_type(
            bounds, TILE_TYPES["WALL"])

        results.append(bounds_are_walls_result)
        print("bounds_are_walls_result: " + str(bounds_are_walls_result))

        # Evaluate cells next to bounds of tilemap are corridors
        corridor_bounds = Bounds(bounds.x_min + 1, bounds.y_min + 1,
                                 bounds.x_max - 1, bounds.y_max - 1)
        next_to_bounds_are_corridors_result = self.evaluate_bounds_are_of_type(
            corridor_bounds, TILE_TYPES["CORRIDOR"])

        results.append(next_to_bounds_are_corridors_result)
        print("next_to_bounds_are_corridors_result: " +
              str(next_to_bounds_are_corridors_result))

        # Evaluate if there are any rooms in the dungeon
        room_bounds = Bounds(bounds.x_min + 2, bounds.y_min + 2,
                             bounds.x_max - 2, bounds.y_max - 2)
        number_of_rooms_result = self.evaluate_rooms(room_bounds)

        results.append(number_of_rooms_result)
        print("number_of_rooms_result: " + str(number_of_rooms_result))

        # Evaluate the cells in room areas
        room_area_result = self.evaluate_room_areas(self.rooms)
        results.append(room_area_result)

        print("room_area_result: " + str(room_area_result))

        self.total_score(results)
Exemplo n.º 4
0
 def getObjectInBounds(self, latlng):
     """
     TODO: Improve the efficienty of this function
     Get the object within the latlng bounds of {latlng}
     """
     
     # Get a bounding box for a geosearch.
     b = Bounds.createBoundsFromAMFData(latlng)
     box = b.asBox()
     
     # The list of road
     listOfObjects = []
     for obj in [Road, Portal, Tower]:
         
         # Get all of the objects with the bounds
         o = obj.bounding_box_fetch(obj.all(), box, max_results = 1000)
         listOfObjects.extend(o)
     logging.error(str(listOfObjects))
     return ArrayCollection(listOfObjects)