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.79 by elmex, Fri Jan 5 14:17:49 2007 UTC vs.
Revision 1.85 by root, Wed Feb 7 00:44:18 2007 UTC

199 while (my ($k, $v) = each %attack_mask) { 199 while (my ($k, $v) = each %attack_mask) {
200 $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;
201 } 201 }
202} 202}
203 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
204# object as in "Object xxx", i.e. archetypes 235# object as in "Object xxx", i.e. archetypes
205sub normalize_object($) { 236sub normalize_object($) {
206 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 }
207 257
208 # nuke outdated or never supported fields 258 # nuke outdated or never supported fields
209 delete @$ob{qw( 259 delete @$ob{qw(
210 can_knockback can_parry can_impale can_cut can_dam_armour 260 can_knockback can_parry can_impale can_cut can_dam_armour
211 can_apply pass_thru can_pass_thru 261 can_apply pass_thru can_pass_thru
384sub read_arch($;$) { 434sub read_arch($;$) {
385 my ($path, $toplevel) = @_; 435 my ($path, $toplevel) = @_;
386 436
387 my %arc; 437 my %arc;
388 my ($more, $prev); 438 my ($more, $prev);
439 my $comment;
389 440
390 open my $fh, "<:raw:perlio:utf8", $path 441 open my $fh, "<:raw:perlio:utf8", $path
391 or Carp::croak "$path: $!"; 442 or Carp::croak "$path: $!";
392 443
393# binmode $fh; 444# binmode $fh;
397 448
398 while (<$fh>) { 449 while (<$fh>) {
399 s/\s+$//; 450 s/\s+$//;
400 if (/^end$/i) { 451 if (/^end$/i) {
401 last; 452 last;
453
402 } elsif (/^arch (\S+)$/i) { 454 } elsif (/^arch (\S+)$/i) {
403 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); 455 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
456
404 } elsif (/^lore$/i) { 457 } elsif (/^lore$/i) {
405 while (<$fh>) { 458 while (<$fh>) {
406 last if /^endlore\s*$/i; 459 last if /^endlore\s*$/i;
407 $arc{lore} .= $_; 460 $arc{lore} .= $_;
408 } 461 }
417 chomp; 470 chomp;
418 push @{ $arc{anim} }, $_; 471 push @{ $arc{anim} }, $_;
419 } 472 }
420 } elsif (/^(\S+)\s*(.*)$/) { 473 } elsif (/^(\S+)\s*(.*)$/) {
421 $arc{lc $1} = $2; 474 $arc{lc $1} = $2;
422 } elsif (/^\s*($|#)/) { 475 } elsif (/^\s*#/) {
476 $arc{_comment} .= "$_\n";
477
478 } elsif (/^\s*$/) {
423 # 479 #
424 } else { 480 } else {
425 warn "$path: unparsable line '$_' in arch $arc{_name}"; 481 warn "$path: unparsable line '$_' in arch $arc{_name}";
426 } 482 }
427 } 483 }
433 s/\s+$//; 489 s/\s+$//;
434 if (/^more$/i) { 490 if (/^more$/i) {
435 $more = $prev; 491 $more = $prev;
436 } elsif (/^object (\S+)$/i) { 492 } elsif (/^object (\S+)$/i) {
437 my $name = $1; 493 my $name = $1;
438 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};
439 $arc->{_atype} = 'object'; 497 $arc->{_atype} = 'object';
440 498
441 if ($more) { 499 if ($more) {
442 $more->{more} = $arc; 500 $more->{more} = $arc;
443 } else { 501 } else {
445 } 503 }
446 $prev = $arc; 504 $prev = $arc;
447 $more = undef; 505 $more = undef;
448 } elsif (/^arch (\S+)$/i) { 506 } elsif (/^arch (\S+)$/i) {
449 my $name = $1; 507 my $name = $1;
450 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};
451 $arc->{_atype} = 'arch'; 511 $arc->{_atype} = 'arch';
452 512
453 if ($more) { 513 if ($more) {
454 $more->{more} = $arc; 514 $more->{more} = $arc;
455 } else { 515 } else {
464 push @{$toplevel->{lev_array}}, $_+0; 524 push @{$toplevel->{lev_array}}, $_+0;
465 } 525 }
466 } else { 526 } else {
467 $toplevel->{$1} = $2; 527 $toplevel->{$1} = $2;
468 } 528 }
529 } elsif (/^\s*#/) {
530 $comment .= "$_\n";
469 } elsif (/^\s*($|#)/) { 531 } elsif (/^\s*($|#)/) {
470 # 532 #
471 } else { 533 } else {
472 die "$path: unparseable top-level line '$_'"; 534 die "$path: unparseable top-level line '$_'";
473 } 535 }
493 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}) {
494 $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) 556 $a{attack_movement} = (delete $a{attack_movement_bits_0_3})
495 | (delete $a{attack_movement_bits_4_7}); 557 | (delete $a{attack_movement_bits_4_7});
496 } 558 }
497 559
560 if (my $comment = delete $a{_comment}) {
561 if ($comment =~ /[^\n\s#]/) {
562 $str .= $comment;
563 }
564 }
565
498 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; 566 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n";
499 567
500 my $inv = delete $a{inventory}; 568 my $inv = delete $a{inventory};
501 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
502 my $anim = delete $a{anim}; 570 my $anim = delete $a{anim};
503 571
504 my @kv; 572 my @kv;
505 573
561 if $anim; 629 if $anim;
562 } 630 }
563 631
564 $str .= "end\n"; 632 $str .= "end\n";
565 633
566 if (($a{_atype} eq 'object') && $more) { 634 if ($a{_atype} eq 'object') {
635 if ($more) {
567 $str .= "\nmore\n"; 636 $str .= "more\n";
568 $append->($more) if $more; 637 $append->($more) if $more;
638 } else {
639 $str .= "\n";
640 }
569 } 641 }
570 }; 642 };
571 643
572 for (@$arch) { 644 for (@$arch) {
573 $append->($_); 645 $append->($_);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines