--- deliantra/Deliantra/Deliantra.pm 2006/02/06 23:01:31 1.10 +++ deliantra/Deliantra/Deliantra.pm 2006/02/07 14:30:08 1.11 @@ -14,7 +14,13 @@ use Storable; -our @EXPORT = qw(read_pak read_arch arch2map $ARCH TILESIZE editor_archs arch2pickmap arch_extends); +#XXX: The map_* procedures scream for a map-object + +our @EXPORT = + qw(read_pak read_arch arch2map $ARCH TILESIZE editor_archs + arch2pickmap arch_extends + map_get_tile_stack map_push_tile_stack map_pop_tile_stack + ); our $LIB = $ENV{CROSSFIRE_LIBDIR} or die "\$CROSSFIRE_LIBDIR must be set\n"; @@ -126,6 +132,43 @@ } } +# returns the arch/object stack from a tile on a map +sub map_get_tile_stack { + my ($map, $x, $y) = @_; + my $as; + + if ($x > 0 || $x < $map->{width} + || $y > 0 || $y < $map->{height}) { + + $as = $map->{map}{map}[$x][$y] || []; + } + + return $as; +} + +# pop the topmost arch/object from the stack of a tile on a map +sub map_pop_tile_stack { + my ($map, $x, $y) = @_; + + if ($x > 0 || $x < $map->{width} + || $y > 0 || $y < $map->{height}) { + + pop @{$map->{map}{map}[$x][$y]}; + } +} + +# pushes the arch/object on the stack of a tile on a map +sub map_push_tile_stack { + my ($map, $x, $y, $arch) = @_; + + if ($x > 0 || $x < $map->{width} + || $y > 0 || $y < $map->{height}) { + + push @{$map->{map}{map}[$x][$y]}, $arch; + } +} + + # put all archs into a hash with editor_face as it's key # NOTE: the arrays in the hash values are references to # the archs from $ARCH