… | |
… | |
388 | if (/^more$/i) { |
388 | if (/^more$/i) { |
389 | $more = $prev; |
389 | $more = $prev; |
390 | } elsif (/^object (\S+)$/i) { |
390 | } elsif (/^object (\S+)$/i) { |
391 | my $name = $1; |
391 | my $name = $1; |
392 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name); |
392 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name); |
|
|
393 | $arc->{_atype} = 'object'; |
393 | |
394 | |
394 | if ($more) { |
395 | if ($more) { |
395 | $more->{more} = $arc; |
396 | $more->{more} = $arc; |
396 | } else { |
397 | } else { |
397 | $arc{$name} = $arc; |
398 | $arc{$name} = $arc; |
… | |
… | |
399 | $prev = $arc; |
400 | $prev = $arc; |
400 | $more = undef; |
401 | $more = undef; |
401 | } elsif (/^arch (\S+)$/i) { |
402 | } elsif (/^arch (\S+)$/i) { |
402 | my $name = $1; |
403 | my $name = $1; |
403 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); |
404 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); |
|
|
405 | $arc->{_atype} = 'arch'; |
404 | |
406 | |
405 | if ($more) { |
407 | if ($more) { |
406 | $more->{more} = $arc; |
408 | $more->{more} = $arc; |
407 | } else { |
409 | } else { |
408 | push @{ $arc{arch} }, $arc; |
410 | push @{ $arc{arch} }, $arc; |
… | |
… | |
426 | } |
428 | } |
427 | |
429 | |
428 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
430 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
429 | |
431 | |
430 | \%arc |
432 | \%arc |
|
|
433 | } |
|
|
434 | |
|
|
435 | sub archlist_to_string { |
|
|
436 | my ($arch) = @_; |
|
|
437 | |
|
|
438 | my $str; |
|
|
439 | |
|
|
440 | my $append; $append = sub { |
|
|
441 | my %a = %{$_[0]}; |
|
|
442 | |
|
|
443 | Crossfire::attr_freeze \%a; |
|
|
444 | Crossfire::normalize_arch \%a; |
|
|
445 | |
|
|
446 | # undo the bit-split we did before |
|
|
447 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
|
|
448 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
|
|
449 | | (delete $a{attack_movement_bits_4_7}); |
|
|
450 | } |
|
|
451 | |
|
|
452 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
|
|
453 | |
|
|
454 | my $inv = delete $a{inventory}; |
|
|
455 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
|
|
456 | my $anim = delete $a{anim}; |
|
|
457 | |
|
|
458 | my @kv; |
|
|
459 | |
|
|
460 | for ($a{_name} eq "map" |
|
|
461 | ? @Crossfire::FIELD_ORDER_MAP |
|
|
462 | : @Crossfire::FIELD_ORDER) { |
|
|
463 | push @kv, [$_, delete $a{$_}] |
|
|
464 | if exists $a{$_}; |
|
|
465 | } |
|
|
466 | |
|
|
467 | for (sort keys %a) { |
|
|
468 | next if /^_/; # ignore our _-keys |
|
|
469 | push @kv, [$_, delete $a{$_}]; |
|
|
470 | } |
|
|
471 | |
|
|
472 | for (@kv) { |
|
|
473 | my ($k, $v) = @$_; |
|
|
474 | |
|
|
475 | if (my $end = $Crossfire::FIELD_MULTILINE{$k}) { |
|
|
476 | $v =~ s/\n$//; |
|
|
477 | $str .= "$k\n$v\n$end\n"; |
|
|
478 | } elsif (exists $Crossfire::FIELD_MOVEMENT{$k}) { |
|
|
479 | if ($v & ~Crossfire::MOVE_ALL or !$v) { |
|
|
480 | $str .= "$k $v\n"; |
|
|
481 | |
|
|
482 | } elsif ($v & Crossfire::MOVE_ALLBIT) { |
|
|
483 | $str .= "$k all"; |
|
|
484 | |
|
|
485 | $str .= " -walk" unless $v & Crossfire::MOVE_WALK; |
|
|
486 | $str .= " -fly_low" unless $v & Crossfire::MOVE_FLY_LOW; |
|
|
487 | $str .= " -fly_high" unless $v & Crossfire::MOVE_FLY_HIGH; |
|
|
488 | $str .= " -swim" unless $v & Crossfire::MOVE_SWIM; |
|
|
489 | $str .= " -boat" unless $v & Crossfire::MOVE_BOAT; |
|
|
490 | |
|
|
491 | $str .= "\n"; |
|
|
492 | |
|
|
493 | } else { |
|
|
494 | $str .= $k; |
|
|
495 | |
|
|
496 | $str .= " walk" if $v & Crossfire::MOVE_WALK; |
|
|
497 | $str .= " fly_low" if $v & Crossfire::MOVE_FLY_LOW; |
|
|
498 | $str .= " fly_high" if $v & Crossfire::MOVE_FLY_HIGH; |
|
|
499 | $str .= " swim" if $v & Crossfire::MOVE_SWIM; |
|
|
500 | $str .= " boat" if $v & Crossfire::MOVE_BOAT; |
|
|
501 | |
|
|
502 | $str .= "\n"; |
|
|
503 | } |
|
|
504 | } else { |
|
|
505 | $str .= "$k $v\n"; |
|
|
506 | } |
|
|
507 | } |
|
|
508 | |
|
|
509 | if ($inv) { |
|
|
510 | $append->($_) for @$inv; |
|
|
511 | } |
|
|
512 | |
|
|
513 | if ($a{_atype} eq 'object') { |
|
|
514 | $str .= join "\n", "anim", @$anim, "mina\n" |
|
|
515 | if $anim; |
|
|
516 | } |
|
|
517 | |
|
|
518 | $str .= "end\n"; |
|
|
519 | |
|
|
520 | if (($a{_atype} eq 'object') && $more) { |
|
|
521 | $str .= "\nmore\n"; |
|
|
522 | $append->($more) if $more; |
|
|
523 | } |
|
|
524 | }; |
|
|
525 | |
|
|
526 | for (@$arch) { |
|
|
527 | $append->($_); |
|
|
528 | } |
|
|
529 | |
|
|
530 | $str |
431 | } |
531 | } |
432 | |
532 | |
433 | # put all archs into a hash with editor_face as it's key |
533 | # put all archs into a hash with editor_face as it's key |
434 | # NOTE: the arrays in the hash values are references to |
534 | # NOTE: the arrays in the hash values are references to |
435 | # the archs from $ARCH |
535 | # the archs from $ARCH |