ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.9 by root, Sun Feb 5 21:18:07 2006 UTC vs.
Revision 1.12 by root, Thu Feb 9 19:59:29 2006 UTC

12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Storable; 15use Storable;
16 16
17our @EXPORT = qw(read_pak read_arch arch2map $ARCH TILESIZE); 17#XXX: The map_* procedures scream for a map-object
18
19our @EXPORT =
20 qw(read_pak read_arch $ARCH TILESIZE editor_archs
21 arch_extends
22 map_get_tile_stack map_push_tile_stack map_pop_tile_stack
23 );
18 24
19our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
20 or die "\$CROSSFIRE_LIBDIR must be set\n"; 26 or die "\$CROSSFIRE_LIBDIR must be set\n";
21 27
22sub TILESIZE (){ 32 } 28sub TILESIZE (){ 32 }
124 130
125 \%arc 131 \%arc
126 } 132 }
127} 133}
128 134
129sub arch2map($;$) { 135# returns the arch/object stack from a tile on a map
136sub map_get_tile_stack {
137 my ($map, $x, $y) = @_;
138 my $as;
139
140 if ($x > 0 || $x < $map->{width}
141 || $y > 0 || $y < $map->{height}) {
142
143 $as = $map->{map}{map}[$x][$y] || [];
144 }
145
146 return $as;
147}
148
149# pop the topmost arch/object from the stack of a tile on a map
150sub map_pop_tile_stack {
151 my ($map, $x, $y) = @_;
152
153 if ($x > 0 || $x < $map->{width}
154 || $y > 0 || $y < $map->{height}) {
155
156 pop @{$map->{map}{map}[$x][$y]};
157 }
158}
159
160# pushes the arch/object on the stack of a tile on a map
161sub map_push_tile_stack {
162 my ($map, $x, $y, $arch) = @_;
163
164 if ($x > 0 || $x < $map->{width}
165 || $y > 0 || $y < $map->{height}) {
166
167 push @{$map->{map}{map}[$x][$y]}, $arch;
168 }
169}
170
171
172# put all archs into a hash with editor_face as it's key
173# NOTE: the arrays in the hash values are references to
174# the archs from $ARCH
175sub editor_archs {
176 my %paths;
177
178 for (keys %$ARCH) {
179 my $arch = $ARCH->{$_};
180 push @{$paths{$arch->{editor_folder}}}, \$arch;
181 }
182
183 return \%paths;
184}
185
186# arch_extends determines how the arch looks like on the map,
187# bigfaces, linked faces and single faces are handled here
188# it returns (<xoffset>, <yoffset>, <width>, <height>)
189# NOTE: non rectangular linked faces are not considered
190sub arch_extends {
130 my ($mapa) = @_; 191 my ($a) = @_;
131 192
132 my %meta; 193 my $TC = \%Crossfire::Tilecache::TILECACHE;
133 194
134 my ($mapx, $mapy); 195 my $facename =
196 $a->{face} || $ARCH->{$a->{_name}}->{face}
197 or return ();
135 198
136 my $map; 199 my $tile = $TC->{$facename}
200 or (warn "no gfx found for arch '$facename' in arch_size ()"), return;
137 201
138 for (@{ $mapa->{arch} }) { 202 if ($tile->{w} > 1 || $tile->{h} > 1) {
139 my ($x, $y) = (delete $_->{x}, delete $_->{y}); 203 # bigfaces
204 return (0, 0, $tile->{w}, $tile->{h});
140 205
141 if ($_->{_name} eq "map") { 206 } elsif ($a->{more}) {
142 $meta{info} = $_; 207 # linked faces
208 my ($miw, $mih, $maw, $mah) = (0, 0, 0, 0);
209 do {
210 $miw > (0 + $a->{x}) and $miw = $a->{x};
211 $mih > (0 + $a->{y}) and $mih = $a->{y};
212 $maw < (0 + $a->{x}) and $maw = $a->{x};
213 $mah < (0 + $a->{y}) and $mah = $a->{y};
214 } while $a = $a->{more};
143 215
144 $mapx = $_->{width} || $x; 216 return ($miw, $mih, ($maw - $miw) + 1, ($mah - $mih) + 1)
145 $mapy = $_->{height} || $y; 217
146 } else { 218 } else {
147 push @{ $map->[$x][$y] }, $_; 219 # single face
148 220 return (0, 0, 1, 1);
149 # arch map is unreliable w.r.t. width and height
150 $mapx = $x + 1 if $mapx <= $x;
151 $mapy = $y + 1 if $mapy <= $y;
152 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
153 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
154 }
155 } 221 }
156
157 $meta{width} = $mapx;
158 $meta{height} = $mapy;
159 $meta{map} = $map;
160
161 \%meta
162} 222}
163 223
164sub init($) { 224sub init($) {
165 my ($cachedir) = @_; 225 my ($cachedir) = @_;
166 226

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines