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.72 by root, Mon Sep 4 17:58:51 2006 UTC vs.
Revision 1.81 by root, Tue Feb 6 22:27:44 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '0.9'; 9our $VERSION = '0.96';
10 10
11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
33 JSON::Syck::Dump $_[0] 33 JSON::Syck::Dump $_[0]
34} 34}
35 35
36our $LIB = $ENV{CROSSFIRE_LIBDIR}; 36our $LIB = $ENV{CROSSFIRE_LIBDIR};
37 37
38our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; 38our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire"
39 : $ENV{AppData} ? "$ENV{APPDATA}/crossfire"
40 : File::Spec->tmpdir . "/crossfire";
39 41
40mkdir $VARDIR, 0777; 42mkdir $VARDIR, 0777;
41 43
42sub TILESIZE (){ 32 } 44sub TILESIZE (){ 32 }
43 45
193 195
194sub _add_resist($$$) { 196sub _add_resist($$$) {
195 my ($ob, $mask, $value) = @_; 197 my ($ob, $mask, $value) = @_;
196 198
197 while (my ($k, $v) = each %attack_mask) { 199 while (my ($k, $v) = each %attack_mask) {
198 $ob->{"resist_$k"} += $value if $mask & $v; 200 $ob->{"resist_$k"} = min 100, max -100, $ob->{"resist_$k"} + $value if $mask & $v;
199 } 201 }
200} 202}
201 203
202# object as in "Object xxx", i.e. archetypes 204# object as in "Object xxx", i.e. archetypes
203sub normalize_object($) { 205sub normalize_object($) {
288 slaying => delete $ob->{"event_${event}"}, 290 slaying => delete $ob->{"event_${event}"},
289 name => delete $ob->{"event_${event}_options"}, 291 name => delete $ob->{"event_${event}_options"},
290 }; 292 };
291 } 293 }
292 } 294 }
295
296 # some archetypes had "+3" instead of the canonical "3", so fix
297 $ob->{dam} *= 1 if exists $ob->{dam};
293 298
294 $ob 299 $ob
295} 300}
296 301
297# arch as in "arch xxx", ie.. objects 302# arch as in "arch xxx", ie.. objects
379sub read_arch($;$) { 384sub read_arch($;$) {
380 my ($path, $toplevel) = @_; 385 my ($path, $toplevel) = @_;
381 386
382 my %arc; 387 my %arc;
383 my ($more, $prev); 388 my ($more, $prev);
389 my $comment;
384 390
385 open my $fh, "<:raw:perlio:utf8", $path 391 open my $fh, "<:raw:perlio:utf8", $path
386 or Carp::croak "$path: $!"; 392 or Carp::croak "$path: $!";
387 393
388# binmode $fh; 394# binmode $fh;
392 398
393 while (<$fh>) { 399 while (<$fh>) {
394 s/\s+$//; 400 s/\s+$//;
395 if (/^end$/i) { 401 if (/^end$/i) {
396 last; 402 last;
403
397 } elsif (/^arch (\S+)$/i) { 404 } elsif (/^arch (\S+)$/i) {
398 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); 405 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
406
399 } elsif (/^lore$/i) { 407 } elsif (/^lore$/i) {
400 while (<$fh>) { 408 while (<$fh>) {
401 last if /^endlore\s*$/i; 409 last if /^endlore\s*$/i;
402 $arc{lore} .= $_; 410 $arc{lore} .= $_;
403 } 411 }
412 chomp; 420 chomp;
413 push @{ $arc{anim} }, $_; 421 push @{ $arc{anim} }, $_;
414 } 422 }
415 } elsif (/^(\S+)\s*(.*)$/) { 423 } elsif (/^(\S+)\s*(.*)$/) {
416 $arc{lc $1} = $2; 424 $arc{lc $1} = $2;
417 } elsif (/^\s*($|#)/) { 425 } elsif (/^\s*#/) {
426 $arc{_comment} .= "$_\n";
427
428 } elsif (/^\s*$/) {
418 # 429 #
419 } else { 430 } else {
420 warn "$path: unparsable line '$_' in arch $arc{_name}"; 431 warn "$path: unparsable line '$_' in arch $arc{_name}";
421 } 432 }
422 } 433 }
428 s/\s+$//; 439 s/\s+$//;
429 if (/^more$/i) { 440 if (/^more$/i) {
430 $more = $prev; 441 $more = $prev;
431 } elsif (/^object (\S+)$/i) { 442 } elsif (/^object (\S+)$/i) {
432 my $name = $1; 443 my $name = $1;
433 my $arc = attr_thaw normalize_object $parse_block->(_name => $name); 444 my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment);
445 undef $comment;
446 delete $arc{_comment} unless length $arc{_comment};
434 $arc->{_atype} = 'object'; 447 $arc->{_atype} = 'object';
435 448
436 if ($more) { 449 if ($more) {
437 $more->{more} = $arc; 450 $more->{more} = $arc;
438 } else { 451 } else {
440 } 453 }
441 $prev = $arc; 454 $prev = $arc;
442 $more = undef; 455 $more = undef;
443 } elsif (/^arch (\S+)$/i) { 456 } elsif (/^arch (\S+)$/i) {
444 my $name = $1; 457 my $name = $1;
445 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); 458 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment);
459 undef $comment;
460 delete $arc{_comment} unless length $arc{_comment};
446 $arc->{_atype} = 'arch'; 461 $arc->{_atype} = 'arch';
447 462
448 if ($more) { 463 if ($more) {
449 $more->{more} = $arc; 464 $more->{more} = $arc;
450 } else { 465 } else {
459 push @{$toplevel->{lev_array}}, $_+0; 474 push @{$toplevel->{lev_array}}, $_+0;
460 } 475 }
461 } else { 476 } else {
462 $toplevel->{$1} = $2; 477 $toplevel->{$1} = $2;
463 } 478 }
479 } elsif (/^\s*#/) {
480 $comment .= "$_\n";
464 } elsif (/^\s*($|#)/) { 481 } elsif (/^\s*($|#)/) {
465 # 482 #
466 } else { 483 } else {
467 die "$path: unparseable top-level line '$_'"; 484 die "$path: unparseable top-level line '$_'";
468 } 485 }
488 if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { 505 if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) {
489 $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) 506 $a{attack_movement} = (delete $a{attack_movement_bits_0_3})
490 | (delete $a{attack_movement_bits_4_7}); 507 | (delete $a{attack_movement_bits_4_7});
491 } 508 }
492 509
510 if (my $comment = delete $a{_comment}) {
511 if ($comment =~ /[^\n\s#]/) {
512 $str .= $comment;
513 }
514 }
515
493 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; 516 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n";
494 517
495 my $inv = delete $a{inventory}; 518 my $inv = delete $a{inventory};
496 my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some 519 my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some
497 my $anim = delete $a{anim}; 520 my $anim = delete $a{anim};
498 521
499 my @kv; 522 my @kv;
500 523
556 if $anim; 579 if $anim;
557 } 580 }
558 581
559 $str .= "end\n"; 582 $str .= "end\n";
560 583
561 if (($a{_atype} eq 'object') && $more) { 584 if ($a{_atype} eq 'object') {
585 if ($more) {
562 $str .= "\nmore\n"; 586 $str .= "more\n";
563 $append->($more) if $more; 587 $append->($more) if $more;
588 } else {
589 $str .= "\n";
590 }
564 } 591 }
565 }; 592 };
566 593
567 for (@$arch) { 594 for (@$arch) {
568 $append->($_); 595 $append->($_);
597 my ($a) = @_; 624 my ($a) = @_;
598 625
599 my $o = $ARCH{$a->{_name}} 626 my $o = $ARCH{$a->{_name}}
600 or return; 627 or return;
601 628
602 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} 629 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"};
630 unless ($face) {
631 $face = $FACE{"blank.x11"}
603 or (warn "no face data found for arch '$a->{_name}'"), return; 632 or (warn "no face data found for arch '$a->{_name}'"), return;
633 }
604 634
605 if ($face->{w} > 1 || $face->{h} > 1) { 635 if ($face->{w} > 1 || $face->{h} > 1) {
606 # bigface 636 # bigface
607 return (0, 0, $face->{w} - 1, $face->{h} - 1); 637 return (0, 0, $face->{w} - 1, $face->{h} - 1);
608 638

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines