… | |
… | |
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 | |
|
|
204 | my %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 | blood => 544, |
|
|
231 | ; |
|
|
232 | |
204 | # object as in "Object xxx", i.e. archetypes |
233 | # object as in "Object xxx", i.e. archetypes |
205 | sub normalize_object($) { |
234 | sub normalize_object($) { |
206 | my ($ob) = @_; |
235 | my ($ob) = @_; |
|
|
236 | |
|
|
237 | # convert material bitset to materialname, if possible |
|
|
238 | if (exists $ob->{material}) { |
|
|
239 | if (!$ob->{material}) { |
|
|
240 | delete $ob->{material}; |
|
|
241 | } elsif (exists $ob->{materialname}) { |
|
|
242 | if ($MATERIAL{$ob->{material}} eq $ob->{materialname}) { |
|
|
243 | delete $ob->{material}; |
|
|
244 | } else { |
|
|
245 | warn "object $ob->{_name} has both materialname ($ob->{materialname}) and material ($ob->{material}) set.\n"; |
|
|
246 | delete $ob->{material}; # assume materilname is more specific and nuke material |
|
|
247 | } |
|
|
248 | } elsif (my $name = $MATERIAL{$ob->{material}}) { |
|
|
249 | delete $ob->{material}; |
|
|
250 | $ob->{materialname} = $name; |
|
|
251 | } else { |
|
|
252 | warn "object $ob->{_name} has unknown material ($ob->{material}) set.\n"; |
|
|
253 | } |
|
|
254 | } |
207 | |
255 | |
208 | # nuke outdated or never supported fields |
256 | # nuke outdated or never supported fields |
209 | delete @$ob{qw( |
257 | delete @$ob{qw( |
210 | can_knockback can_parry can_impale can_cut can_dam_armour |
258 | can_knockback can_parry can_impale can_cut can_dam_armour |
211 | can_apply pass_thru can_pass_thru |
259 | can_apply pass_thru can_pass_thru |
… | |
… | |
421 | push @{ $arc{anim} }, $_; |
469 | push @{ $arc{anim} }, $_; |
422 | } |
470 | } |
423 | } elsif (/^(\S+)\s*(.*)$/) { |
471 | } elsif (/^(\S+)\s*(.*)$/) { |
424 | $arc{lc $1} = $2; |
472 | $arc{lc $1} = $2; |
425 | } elsif (/^\s*#/) { |
473 | } elsif (/^\s*#/) { |
426 | $arc{_comment} .= $_; |
474 | $arc{_comment} .= "$_\n"; |
427 | |
475 | |
428 | } elsif (/^\s*$/) { |
476 | } elsif (/^\s*$/) { |
429 | # |
477 | # |
430 | } else { |
478 | } else { |
431 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
479 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
… | |
… | |
437 | |
485 | |
438 | while (<$fh>) { |
486 | while (<$fh>) { |
439 | s/\s+$//; |
487 | s/\s+$//; |
440 | if (/^more$/i) { |
488 | if (/^more$/i) { |
441 | $more = $prev; |
489 | $more = $prev; |
442 | } elsif (/^\s*#/) { |
|
|
443 | $comment .= $_; |
|
|
444 | } elsif (/^object (\S+)$/i) { |
490 | } elsif (/^object (\S+)$/i) { |
445 | my $name = $1; |
491 | my $name = $1; |
446 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
492 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
|
|
493 | undef $comment; |
447 | delete $arc{_comment} unless length $arc{_comment}; |
494 | delete $arc{_comment} unless length $arc{_comment}; |
448 | $arc->{_atype} = 'object'; |
495 | $arc->{_atype} = 'object'; |
449 | |
496 | |
450 | if ($more) { |
497 | if ($more) { |
451 | $more->{more} = $arc; |
498 | $more->{more} = $arc; |
… | |
… | |
455 | $prev = $arc; |
502 | $prev = $arc; |
456 | $more = undef; |
503 | $more = undef; |
457 | } elsif (/^arch (\S+)$/i) { |
504 | } elsif (/^arch (\S+)$/i) { |
458 | my $name = $1; |
505 | my $name = $1; |
459 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
506 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
|
|
507 | undef $comment; |
460 | delete $arc{_comment} unless length $arc{_comment}; |
508 | delete $arc{_comment} unless length $arc{_comment}; |
461 | $arc->{_atype} = 'arch'; |
509 | $arc->{_atype} = 'arch'; |
462 | |
510 | |
463 | if ($more) { |
511 | if ($more) { |
464 | $more->{more} = $arc; |
512 | $more->{more} = $arc; |
… | |
… | |
474 | push @{$toplevel->{lev_array}}, $_+0; |
522 | push @{$toplevel->{lev_array}}, $_+0; |
475 | } |
523 | } |
476 | } else { |
524 | } else { |
477 | $toplevel->{$1} = $2; |
525 | $toplevel->{$1} = $2; |
478 | } |
526 | } |
|
|
527 | } elsif (/^\s*#/) { |
|
|
528 | $comment .= "$_\n"; |
479 | } elsif (/^\s*($|#)/) { |
529 | } elsif (/^\s*($|#)/) { |
480 | # |
530 | # |
481 | } else { |
531 | } else { |
482 | die "$path: unparseable top-level line '$_'"; |
532 | die "$path: unparseable top-level line '$_'"; |
483 | } |
533 | } |
… | |
… | |
503 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
553 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
504 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
554 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
505 | | (delete $a{attack_movement_bits_4_7}); |
555 | | (delete $a{attack_movement_bits_4_7}); |
506 | } |
556 | } |
507 | |
557 | |
|
|
558 | if (my $comment = delete $a{_comment}) { |
|
|
559 | if ($comment =~ /[^\n\s#]/) { |
|
|
560 | $str .= $comment; |
|
|
561 | } |
|
|
562 | } |
|
|
563 | |
508 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
564 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
509 | |
565 | |
510 | my $inv = delete $a{inventory}; |
566 | my $inv = delete $a{inventory}; |
511 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
567 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
512 | my $anim = delete $a{anim}; |
568 | my $anim = delete $a{anim}; |
513 | |
569 | |
514 | my @kv; |
570 | my @kv; |
515 | |
571 | |
… | |
… | |
571 | if $anim; |
627 | if $anim; |
572 | } |
628 | } |
573 | |
629 | |
574 | $str .= "end\n"; |
630 | $str .= "end\n"; |
575 | |
631 | |
576 | if (($a{_atype} eq 'object') && $more) { |
632 | if ($a{_atype} eq 'object') { |
|
|
633 | if ($more) { |
577 | $str .= "\nmore\n"; |
634 | $str .= "more\n"; |
578 | $append->($more) if $more; |
635 | $append->($more) if $more; |
|
|
636 | } else { |
|
|
637 | $str .= "\n"; |
|
|
638 | } |
579 | } |
639 | } |
580 | }; |
640 | }; |
581 | |
641 | |
582 | for (@$arch) { |
642 | for (@$arch) { |
583 | $append->($_); |
643 | $append->($_); |