def get_contents(self, coordinates = None): """ Return a list of the contents of a sector at the provided coordinates. """ if not coordinates or not isinstance(coordinates,Coordinates): self.log.warning("%s called without proper coordinates: %s (type %s)" % ( "Game.get_contents()", str(coordinates), str(coordinates.__class__.__name__), )) return [] contents = [] self.log.debug("Building content list for %s..." % str(coordinates)) # GameObject -> ManMade or Natural -> Object we want here for parent in GameObject.__subclasses__(): self.log.debug("Processing %s objects..." % str(parent)) for child in globals()[parent.__name__].__subclasses__(): self.log.debug("Processing %s objects under %s..." % (str(child),str(parent))) # subclasses returns full path, ex: objects.star.Star # child.__name__ returns Star shared_object = getattr(Game,'_' + globals()[child.__name__]().plural()) if shared_object and coordinates in shared_object: contents += shared_object[coordinates] self.log.debug("Added %s to contents: %s" % ( str(globals()[child.__name__]().plural()), str(shared_object[coordinates]), )) self.log.debug("Coordinates %s contents: %s" % (str(coordinates),pprint.pformat(contents))) return contents