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.11 by elmex, Tue Feb 7 14:30:08 2006 UTC vs.
Revision 1.12 by root, Thu Feb 9 19:59:29 2006 UTC

15use Storable; 15use Storable;
16 16
17#XXX: The map_* procedures scream for a map-object 17#XXX: The map_* procedures scream for a map-object
18 18
19our @EXPORT = 19our @EXPORT =
20 qw(read_pak read_arch arch2map $ARCH TILESIZE editor_archs 20 qw(read_pak read_arch $ARCH TILESIZE editor_archs
21 arch2pickmap arch_extends 21 arch_extends
22 map_get_tile_stack map_push_tile_stack map_pop_tile_stack 22 map_get_tile_stack map_push_tile_stack map_pop_tile_stack
23 ); 23 );
24 24
25our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
26 or die "\$CROSSFIRE_LIBDIR must be set\n"; 26 or die "\$CROSSFIRE_LIBDIR must be set\n";
219 # single face 219 # single face
220 return (0, 0, 1, 1); 220 return (0, 0, 1, 1);
221 } 221 }
222} 222}
223 223
224# arch2pickmap forms a list of archs to a pickmap
225sub arch2pickmap {
226 my ($archs, $w) = @_;
227
228 # sort archs alphabetiacally
229 my $archs = [ sort { ${$a}->{_name} cmp ${$b}->{_name} } @$archs ];
230
231 $w ||= 10; # default width
232 my $num = @$archs;
233 my $map = { };
234 # overall placement coords
235 my $x = 0;
236 my $y = 0;
237
238 my ($maxh, $maxw) = (0, 0); # maximum sizes, to set map width/height later
239 my $drawn_archs = 1; # line-break counter
240 my $max_line_height = 1;
241
242 for (my $i = 0; $i < $num; $i++) {
243
244 defined ${$archs->[$i]}->{face} or next;
245
246 # check whether this tile was already written (see below at (b))
247 unless (defined $map->{map}[$x][$y]) {
248
249 my ($xoffs, $yoffs, $arch_w, $arch_h) = arch_extends (${$archs->[$i]});
250
251 # these are special placement coords, for chained faces which
252 # have a special placement offset
253 my ($place_x, $place_y) = ($x, $y);
254 $xoffs < 0 and
255 $place_x += -$xoffs;
256 $yoffs < 0 and
257 $place_y += -$yoffs;
258
259 # iterate over the tiles this arch takes
260 # NOTE: Chained archs are maybe not a rectangle, but i don't care
261 # much for that on pickmaps
262
263 for (my $xi = 0; $xi < $arch_w; $xi++) {
264 for (my $yi = 0; $yi < $arch_h; $yi++) {
265
266 my ($lx, $ly) = ($x + $xi, $y + $yi);
267
268 if ($lx == $place_x and $ly == $place_y) {
269 push @{$map->{map}[$place_x][$place_y]}, my $a = ${$archs->[$i]};
270
271 } else {
272
273 # (b): here we set occupied tiles, but without the arch
274 $map->{map}[$lx][$ly] = [];
275 }
276 }
277 }
278 $drawn_archs++;
279
280 $x += $arch_w - 1;
281 $max_line_height < $arch_h
282 and $max_line_height = $arch_h;
283
284 } else {
285 $i--;
286 }
287
288
289 $x++;
290
291 if ($x > $w) {
292
293 $y += $max_line_height;
294 $max_line_height = 1;
295 $x = 0;
296 }
297
298 $maxw < ($x + 1) and $maxw = $x + 1;
299 $maxh < ($y + 1) and $maxh = $y + 1;
300 }
301
302 $map->{height} = $maxh;
303 $map->{width} = $maxw;
304
305 return $map;
306}
307
308sub arch2map($;$) {
309 my ($mapa) = @_;
310
311 my %meta;
312
313 my ($mapx, $mapy);
314
315 my $map;
316
317 for (@{ $mapa->{arch} }) {
318 my ($x, $y) = (delete $_->{x}, delete $_->{y});
319
320 if ($_->{_name} eq "map") {
321 $meta{info} = $_;
322
323 $mapx = $_->{width} || $x;
324 $mapy = $_->{height} || $y;
325 } else {
326 push @{ $map->[$x][$y] }, $_;
327
328 # arch map is unreliable w.r.t. width and height
329 $mapx = $x + 1 if $mapx <= $x;
330 $mapy = $y + 1 if $mapy <= $y;
331 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
332 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
333 }
334 }
335
336 $meta{width} = $mapx;
337 $meta{height} = $mapy;
338 $meta{map} = $map;
339
340 \%meta
341}
342
343sub init($) { 224sub init($) {
344 my ($cachedir) = @_; 225 my ($cachedir) = @_;
345 226
346 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 227 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
347} 228}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines