#!/usr/bin/perl
#use Mooix::Thing;
#use Mooix::Root;
run sub ($) {
	my $this=shift;

	# Exits are typically hidden, but still completable.
	my $exit=$Mooix::Root->concrete->exit;
	
	# Gather nearby objects.
	my @nearby;
	my %contentsseen;
	if ($this->contents) {
		$contentsseen{$this->index}=1;
		push @nearby, $this->contents->list;
	}
	my $loc=$this->location;
	if ($loc) {
		$contentsseen{$loc->index}=1;
		my @list=$loc->contents->list;
		push @nearby, $loc, @list;

		# If the location is itself located somewhere,
		# drill down to that uber-location, and add its contents.
		# This makes things work properly while you're sitting on
		# furniture, etc.
		if ($loc->location) {
			while ($loc->location) {
				$loc=$loc->location;
			}
			$contentsseen{$loc->index}=1;
			@list = $loc->contents->list;
			push @nearby, $loc, @list;
                }
	}

	# Recursively add the contents of every container to the list.
	foreach (@nearby) {
		if (! $contentsseen{$_->index} && $_->contents && ! $_->closed) {
			$contentsseen{$_->index}=1;
			# Newly added objects will be processed as part of
			# this very same loop.
			push @nearby, $_->contents->list;
		}
	}

	# gather names and adjectives
	my %seen;
	my @ret;
	foreach (@nearby) {
		next if $seen{$_->index};
		$seen{$_->index}=1;

		next if $_->hidden && ! $_->isa($exit);

		push @ret, (map { lc $_ } $_->name, $_->alias);
		push @ret, $_->adjective;
	}

	return @ret;
}
