#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	
	# Copy inherited value from parent. Do not let the mass be
	# changed if a parent's mass changes, as that can mess up
	# the whole mass tracking system.
	eval {
		$this->_mass($this->_mass);
	};
	if ($@) {
		# Just a pretty error message.
		$this->croak("cannot init new object (check the callstack)");
	}

	if (! -l $this->id."/location") {
		# Set location field pointing to nowhere. It is
		# probably inherited from the parent (incorrectly,
		# since the new object is not in the parent's location).
		$this->location(undef);
	}
	
	# Set name?
	if ($_{name}) {
		# Always override the parent's field, even if it was the
		# same, so if the parent's name is changed, that does not
		# affect the child.
		$this->name($_{name});
	}

	# Take a copy of the parent's hitpoints.
	$this->hitpoints($this->hitpoints);
	
	return $this;
}
