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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines