… | |
… | |
58 | 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); |
59 | |
59 | |
60 | # same as in server save routine, to (hopefully) be compatible |
60 | # same as in server save routine, to (hopefully) be compatible |
61 | # to the other editors. |
61 | # to the other editors. |
62 | our @FIELD_ORDER_MAP = (qw( |
62 | our @FIELD_ORDER_MAP = (qw( |
|
|
63 | file_format_version |
63 | name attach swap_time reset_timeout fixed_resettime difficulty region |
64 | name attach swap_time reset_timeout fixed_resettime difficulty region |
64 | shopitems shopgreed shopmin shopmax shoprace |
65 | shopitems shopgreed shopmin shopmax shoprace |
65 | darkness width height enter_x enter_y msg maplore |
66 | darkness width height enter_x enter_y msg maplore |
66 | unique template |
67 | unique template |
67 | outdoor temp pressure humid windspeed winddir sky nosmooth |
68 | outdoor temp pressure humid windspeed winddir sky nosmooth |
… | |
… | |
199 | while (my ($k, $v) = each %attack_mask) { |
200 | while (my ($k, $v) = each %attack_mask) { |
200 | $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; |
201 | } |
202 | } |
202 | } |
203 | } |
203 | |
204 | |
|
|
205 | my %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 | |
204 | # object as in "Object xxx", i.e. archetypes |
236 | # object as in "Object xxx", i.e. archetypes |
205 | sub normalize_object($) { |
237 | sub normalize_object($) { |
206 | 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 | } |
207 | |
258 | |
208 | # nuke outdated or never supported fields |
259 | # nuke outdated or never supported fields |
209 | delete @$ob{qw( |
260 | delete @$ob{qw( |
210 | can_knockback can_parry can_impale can_cut can_dam_armour |
261 | can_knockback can_parry can_impale can_cut can_dam_armour |
211 | can_apply pass_thru can_pass_thru |
262 | can_apply pass_thru can_pass_thru |
… | |
… | |
421 | push @{ $arc{anim} }, $_; |
472 | push @{ $arc{anim} }, $_; |
422 | } |
473 | } |
423 | } elsif (/^(\S+)\s*(.*)$/) { |
474 | } elsif (/^(\S+)\s*(.*)$/) { |
424 | $arc{lc $1} = $2; |
475 | $arc{lc $1} = $2; |
425 | } elsif (/^\s*#/) { |
476 | } elsif (/^\s*#/) { |
426 | $arc{_comment} .= $_; |
477 | $arc{_comment} .= "$_\n"; |
427 | |
478 | |
428 | } elsif (/^\s*$/) { |
479 | } elsif (/^\s*$/) { |
429 | # |
480 | # |
430 | } else { |
481 | } else { |
431 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
482 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
… | |
… | |
437 | |
488 | |
438 | while (<$fh>) { |
489 | while (<$fh>) { |
439 | s/\s+$//; |
490 | s/\s+$//; |
440 | if (/^more$/i) { |
491 | if (/^more$/i) { |
441 | $more = $prev; |
492 | $more = $prev; |
442 | } elsif (/^\s*#/) { |
|
|
443 | $comment .= $_; |
|
|
444 | } elsif (/^object (\S+)$/i) { |
493 | } elsif (/^object (\S+)$/i) { |
445 | my $name = $1; |
494 | my $name = $1; |
446 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
495 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
|
|
496 | undef $comment; |
447 | delete $arc{_comment} unless length $arc{_comment}; |
497 | delete $arc{_comment} unless length $arc{_comment}; |
448 | $arc->{_atype} = 'object'; |
498 | $arc->{_atype} = 'object'; |
449 | |
499 | |
450 | if ($more) { |
500 | if ($more) { |
451 | $more->{more} = $arc; |
501 | $more->{more} = $arc; |
… | |
… | |
455 | $prev = $arc; |
505 | $prev = $arc; |
456 | $more = undef; |
506 | $more = undef; |
457 | } elsif (/^arch (\S+)$/i) { |
507 | } elsif (/^arch (\S+)$/i) { |
458 | my $name = $1; |
508 | my $name = $1; |
459 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
509 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
|
|
510 | undef $comment; |
460 | delete $arc{_comment} unless length $arc{_comment}; |
511 | delete $arc{_comment} unless length $arc{_comment}; |
461 | $arc->{_atype} = 'arch'; |
512 | $arc->{_atype} = 'arch'; |
462 | |
513 | |
463 | if ($more) { |
514 | if ($more) { |
464 | $more->{more} = $arc; |
515 | $more->{more} = $arc; |
… | |
… | |
474 | push @{$toplevel->{lev_array}}, $_+0; |
525 | push @{$toplevel->{lev_array}}, $_+0; |
475 | } |
526 | } |
476 | } else { |
527 | } else { |
477 | $toplevel->{$1} = $2; |
528 | $toplevel->{$1} = $2; |
478 | } |
529 | } |
|
|
530 | } elsif (/^\s*#/) { |
|
|
531 | $comment .= "$_\n"; |
479 | } elsif (/^\s*($|#)/) { |
532 | } elsif (/^\s*($|#)/) { |
480 | # |
533 | # |
481 | } else { |
534 | } else { |
482 | die "$path: unparseable top-level line '$_'"; |
535 | die "$path: unparseable top-level line '$_'"; |
483 | } |
536 | } |
… | |
… | |
503 | 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}) { |
504 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
557 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
505 | | (delete $a{attack_movement_bits_4_7}); |
558 | | (delete $a{attack_movement_bits_4_7}); |
506 | } |
559 | } |
507 | |
560 | |
|
|
561 | if (my $comment = delete $a{_comment}) { |
|
|
562 | if ($comment =~ /[^\n\s#]/) { |
|
|
563 | $str .= $comment; |
|
|
564 | } |
|
|
565 | } |
|
|
566 | |
508 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
567 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
509 | |
568 | |
510 | my $inv = delete $a{inventory}; |
569 | my $inv = delete $a{inventory}; |
511 | 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 |
512 | my $anim = delete $a{anim}; |
571 | my $anim = delete $a{anim}; |
513 | |
572 | |
514 | my @kv; |
573 | my @kv; |
515 | |
574 | |
… | |
… | |
571 | if $anim; |
630 | if $anim; |
572 | } |
631 | } |
573 | |
632 | |
574 | $str .= "end\n"; |
633 | $str .= "end\n"; |
575 | |
634 | |
576 | if (($a{_atype} eq 'object') && $more) { |
635 | if ($a{_atype} eq 'object') { |
|
|
636 | if ($more) { |
577 | $str .= "\nmore\n"; |
637 | $str .= "more\n"; |
578 | $append->($more) if $more; |
638 | $append->($more) if $more; |
|
|
639 | } else { |
|
|
640 | $str .= "\n"; |
|
|
641 | } |
579 | } |
642 | } |
580 | }; |
643 | }; |
581 | |
644 | |
582 | for (@$arch) { |
645 | for (@$arch) { |
583 | $append->($_); |
646 | $append->($_); |