#!/usr/bin/perl
#use Fcntl q{:flock};
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;

	# Make sure that this command is not spoofed, just in case.
        if ($_{avatar} != $this) {
		fail "No!"; 
	}
	
	if (! $this->home) {
		fail "You have no home!";
	}
	if ($this->home == $this->location) {
		fail "You're already at home.";
	}
	
	$this->msg('gohome', %_);
	my $oldloc=$this->location;
	# The home.cmd can't tell the parser that this avatar needs locking,
	# so do the locking here.
	my $lock=$this->getlock(LOCK_EX);
	if ($this->physics->move(object => $this, to => $this->home)) {
		$oldloc->msg('home', %_) if ref $oldloc;
		$this->msg('teleport_arrive', %_, skip => $this);
	}
	else {
		fail "For some reason, that doesn't work.";
	}
}
