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.74 by root, Wed Sep 20 15:38:21 2006 UTC vs.
Revision 1.85 by root, Wed Feb 7 00:44:18 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '0.91'; 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
197 while (my ($k, $v) = each %attack_mask) { 199 while (my ($k, $v) = each %attack_mask) {
198 $ob->{"resist_$k"} = min 100, max -100, $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
204my %MATERIAL = reverse
205 paper => 1,
206 iron => 2,
207 glass => 4,
208 leather => 8,
209 wood => 16,
210 organic => 32,
211 stone => 64,
212 cloth => 128,
213 adamant => 256,
214 liquid => 512,
215 tin => 1024,
216 bone => 2048,
217 ice => 4096,
218
219 # guesses
220 runestone => 12,
221 bronze => 18,
222 "ancient wood" => 20,
223 glass => 36,
224 marble => 66,
225 ice => 68,
226 stone => 70,
227 stone => 80,
228 cloth => 136,
229 ironwood => 144,
230 adamantium => 258,
231 glacium => 260,
232 blood => 544,
233;
234
202# object as in "Object xxx", i.e. archetypes 235# object as in "Object xxx", i.e. archetypes
203sub normalize_object($) { 236sub normalize_object($) {
204 my ($ob) = @_; 237 my ($ob) = @_;
238
239 # convert material bitset to materialname, if possible
240 if (exists $ob->{material}) {
241 if (!$ob->{material}) {
242 delete $ob->{material};
243 } elsif (exists $ob->{materialname}) {
244 if ($MATERIAL{$ob->{material}} eq $ob->{materialname}) {
245 delete $ob->{material};
246 } else {
247 warn "object $ob->{_name} has both materialname ($ob->{materialname}) and material ($ob->{material}) set.\n";
248 delete $ob->{material}; # assume materilname is more specific and nuke material
249 }
250 } elsif (my $name = $MATERIAL{$ob->{material}}) {
251 delete $ob->{material};
252 $ob->{materialname} = $name;
253 } else {
254 warn "object $ob->{_name} has unknown material ($ob->{material}) set.\n";
255 }
256 }
205 257
206 # nuke outdated or never supported fields 258 # nuke outdated or never supported fields
207 delete @$ob{qw( 259 delete @$ob{qw(
208 can_knockback can_parry can_impale can_cut can_dam_armour 260 can_knockback can_parry can_impale can_cut can_dam_armour
209 can_apply pass_thru can_pass_thru 261 can_apply pass_thru can_pass_thru
382sub read_arch($;$) { 434sub read_arch($;$) {
383 my ($path, $toplevel) = @_; 435 my ($path, $toplevel) = @_;
384 436
385 my %arc; 437 my %arc;
386 my ($more, $prev); 438 my ($more, $prev);
439 my $comment;
387 440
388 open my $fh, "<:raw:perlio:utf8", $path 441 open my $fh, "<:raw:perlio:utf8", $path
389 or Carp::croak "$path: $!"; 442 or Carp::croak "$path: $!";
390 443
391# binmode $fh; 444# binmode $fh;
395 448
396 while (<$fh>) { 449 while (<$fh>) {
397 s/\s+$//; 450 s/\s+$//;
398 if (/^end$/i) { 451 if (/^end$/i) {
399 last; 452 last;
453
400 } elsif (/^arch (\S+)$/i) { 454 } elsif (/^arch (\S+)$/i) {
401 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); 455 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
456
402 } elsif (/^lore$/i) { 457 } elsif (/^lore$/i) {
403 while (<$fh>) { 458 while (<$fh>) {
404 last if /^endlore\s*$/i; 459 last if /^endlore\s*$/i;
405 $arc{lore} .= $_; 460 $arc{lore} .= $_;
406 } 461 }
415 chomp; 470 chomp;
416 push @{ $arc{anim} }, $_; 471 push @{ $arc{anim} }, $_;
417 } 472 }
418 } elsif (/^(\S+)\s*(.*)$/) { 473 } elsif (/^(\S+)\s*(.*)$/) {
419 $arc{lc $1} = $2; 474 $arc{lc $1} = $2;
420 } elsif (/^\s*($|#)/) { 475 } elsif (/^\s*#/) {
476 $arc{_comment} .= "$_\n";
477
478 } elsif (/^\s*$/) {
421 # 479 #
422 } else { 480 } else {
423 warn "$path: unparsable line '$_' in arch $arc{_name}"; 481 warn "$path: unparsable line '$_' in arch $arc{_name}";
424 } 482 }
425 } 483 }
431 s/\s+$//; 489 s/\s+$//;
432 if (/^more$/i) { 490 if (/^more$/i) {
433 $more = $prev; 491 $more = $prev;
434 } elsif (/^object (\S+)$/i) { 492 } elsif (/^object (\S+)$/i) {
435 my $name = $1; 493 my $name = $1;
436 my $arc = attr_thaw normalize_object $parse_block->(_name => $name); 494 my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment);
495 undef $comment;
496 delete $arc{_comment} unless length $arc{_comment};
437 $arc->{_atype} = 'object'; 497 $arc->{_atype} = 'object';
438 498
439 if ($more) { 499 if ($more) {
440 $more->{more} = $arc; 500 $more->{more} = $arc;
441 } else { 501 } else {
443 } 503 }
444 $prev = $arc; 504 $prev = $arc;
445 $more = undef; 505 $more = undef;
446 } elsif (/^arch (\S+)$/i) { 506 } elsif (/^arch (\S+)$/i) {
447 my $name = $1; 507 my $name = $1;
448 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); 508 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment);
509 undef $comment;
510 delete $arc{_comment} unless length $arc{_comment};
449 $arc->{_atype} = 'arch'; 511 $arc->{_atype} = 'arch';
450 512
451 if ($more) { 513 if ($more) {
452 $more->{more} = $arc; 514 $more->{more} = $arc;
453 } else { 515 } else {
462 push @{$toplevel->{lev_array}}, $_+0; 524 push @{$toplevel->{lev_array}}, $_+0;
463 } 525 }
464 } else { 526 } else {
465 $toplevel->{$1} = $2; 527 $toplevel->{$1} = $2;
466 } 528 }
529 } elsif (/^\s*#/) {
530 $comment .= "$_\n";
467 } elsif (/^\s*($|#)/) { 531 } elsif (/^\s*($|#)/) {
468 # 532 #
469 } else { 533 } else {
470 die "$path: unparseable top-level line '$_'"; 534 die "$path: unparseable top-level line '$_'";
471 } 535 }
491 if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { 555 if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) {
492 $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) 556 $a{attack_movement} = (delete $a{attack_movement_bits_0_3})
493 | (delete $a{attack_movement_bits_4_7}); 557 | (delete $a{attack_movement_bits_4_7});
494 } 558 }
495 559
560 if (my $comment = delete $a{_comment}) {
561 if ($comment =~ /[^\n\s#]/) {
562 $str .= $comment;
563 }
564 }
565
496 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; 566 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n";
497 567
498 my $inv = delete $a{inventory}; 568 my $inv = delete $a{inventory};
499 my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some 569 my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some
500 my $anim = delete $a{anim}; 570 my $anim = delete $a{anim};
501 571
502 my @kv; 572 my @kv;
503 573
559 if $anim; 629 if $anim;
560 } 630 }
561 631
562 $str .= "end\n"; 632 $str .= "end\n";
563 633
564 if (($a{_atype} eq 'object') && $more) { 634 if ($a{_atype} eq 'object') {
635 if ($more) {
565 $str .= "\nmore\n"; 636 $str .= "more\n";
566 $append->($more) if $more; 637 $append->($more) if $more;
638 } else {
639 $str .= "\n";
640 }
567 } 641 }
568 }; 642 };
569 643
570 for (@$arch) { 644 for (@$arch) {
571 $append->($_); 645 $append->($_);
600 my ($a) = @_; 674 my ($a) = @_;
601 675
602 my $o = $ARCH{$a->{_name}} 676 my $o = $ARCH{$a->{_name}}
603 or return; 677 or return;
604 678
605 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} 679 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"};
680 unless ($face) {
681 $face = $FACE{"blank.x11"}
606 or (warn "no face data found for arch '$a->{_name}'"), return; 682 or (warn "no face data found for arch '$a->{_name}'"), return;
683 }
607 684
608 if ($face->{w} > 1 || $face->{h} > 1) { 685 if ($face->{w} > 1 || $face->{h} > 1) {
609 # bigface 686 # bigface
610 return (0, 0, $face->{w} - 1, $face->{h} - 1); 687 return (0, 0, $face->{w} - 1, $face->{h} - 1);
611 688

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines