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.80 by root, Tue Feb 6 22:08:14 2007 UTC vs.
Revision 1.89 by root, Tue Feb 27 23:29:59 2007 UTC

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.
62our @FIELD_ORDER_MAP = (qw( 62our @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
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
204# object as in "Object xxx", i.e. archetypes 236# object as in "Object xxx", i.e. archetypes
205sub normalize_object($) { 237sub 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
254 if (defined (my $v = delete $ob->{slow_move})) { 305 if (defined (my $v = delete $ob->{slow_move})) {
255 $ob->{move_slow} |= MOVE_WALK; 306 $ob->{move_slow} |= MOVE_WALK;
256 $ob->{move_slow_penalty} = $v; 307 $ob->{move_slow_penalty} = $v;
257 } 308 }
258 if (defined (my $v = delete $ob->{walk_on})) { 309 if (defined (my $v = delete $ob->{walk_on})) {
259 $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; 310 $ob->{move_on} = 0 unless exists $ob->{move_on};
260 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK 311 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK
261 : $ob->{move_on} & ~MOVE_WALK; 312 : $ob->{move_on} & ~MOVE_WALK;
262 } 313 }
263 if (defined (my $v = delete $ob->{walk_off})) { 314 if (defined (my $v = delete $ob->{walk_off})) {
264 $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; 315 $ob->{move_off} = 0 unless exists $ob->{move_off};
265 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK 316 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK
266 : $ob->{move_off} & ~MOVE_WALK; 317 : $ob->{move_off} & ~MOVE_WALK;
267 } 318 }
268 if (defined (my $v = delete $ob->{fly_on})) { 319 if (defined (my $v = delete $ob->{fly_on})) {
269 $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; 320 $ob->{move_on} = 0 unless exists $ob->{move_on};
270 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW 321 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW
271 : $ob->{move_on} & ~MOVE_FLY_LOW; 322 : $ob->{move_on} & ~MOVE_FLY_LOW;
272 } 323 }
273 if (defined (my $v = delete $ob->{fly_off})) { 324 if (defined (my $v = delete $ob->{fly_off})) {
274 $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; 325 $ob->{move_off} = 0 unless exists $ob->{move_off};
275 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW 326 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW
276 : $ob->{move_off} & ~MOVE_FLY_LOW; 327 : $ob->{move_off} & ~MOVE_FLY_LOW;
277 } 328 }
278 if (defined (my $v = delete $ob->{flying})) { 329 if (defined (my $v = delete $ob->{flying})) {
279 $ob->{move_type} = MOVE_ALL unless exists $ob->{move_type}; 330 $ob->{move_type} = 0 unless exists $ob->{move_type};
280 $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW 331 $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW
281 : $ob->{move_type} & ~MOVE_FLY_LOW; 332 : $ob->{move_type} & ~MOVE_FLY_LOW;
282 } 333 }
283 334
284 # convert idiotic event_xxx things into objects 335 # convert idiotic event_xxx things into objects
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};
572
573 if ($a{_atype} eq 'object') {
574 $str .= join "\n", "anim", @$anim, "mina\n"
575 if $anim;
576 }
513 577
514 my @kv; 578 my @kv;
515 579
516 for ($a{_name} eq "map" 580 for ($a{_name} eq "map"
517 ? @Crossfire::FIELD_ORDER_MAP 581 ? @Crossfire::FIELD_ORDER_MAP
564 628
565 if ($inv) { 629 if ($inv) {
566 $append->($_) for @$inv; 630 $append->($_) for @$inv;
567 } 631 }
568 632
633 $str .= "end\n";
634
569 if ($a{_atype} eq 'object') { 635 if ($a{_atype} eq 'object') {
570 $str .= join "\n", "anim", @$anim, "mina\n" 636 if ($more) {
571 if $anim;
572 }
573
574 $str .= "end\n";
575
576 if (($a{_atype} eq 'object') && $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->($_);
733 ]; 796 ];
734 797
735 $attr 798 $attr
736} 799}
737 800
738sub arch_edit_sections {
739# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
740# edit_type = 0;
741# else if (edit_type != 0) {
742# // all flags from 'check_type' must be unset in this arch because they get recalculated now
743# edit_type &= ~check_type;
744# }
745#
746# }
747# if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 &&
748# getAttributeValue("alive", defarch) == 1 &&
749# (getAttributeValue("monster", defarch) == 1 ||
750# getAttributeValue("generator", defarch) == 1)) {
751# // Monster: monsters/npcs/generators
752# edit_type |= IGUIConstants.TILE_EDIT_MONSTER;
753# }
754# if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 &&
755# arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) {
756# // Walls
757# edit_type |= IGUIConstants.TILE_EDIT_WALL;
758# }
759# if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 &&
760# getAttributeValue("connected", defarch) != 0) {
761# // Connected Objects
762# edit_type |= IGUIConstants.TILE_EDIT_CONNECTED;
763# }
764# if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 &&
765# arch_type == 66 || arch_type == 41 || arch_type == 95) {
766# // Exit: teleporter/exit/trapdoors
767# edit_type |= IGUIConstants.TILE_EDIT_EXIT;
768# }
769# if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 &&
770# getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 ||
771# arch_type == 5 || arch_type == 36 || arch_type == 60 ||
772# arch_type == 85 || arch_type == 111 || arch_type == 123 ||
773# arch_type == 124 || arch_type == 130)) {
774# // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls
775# edit_type |= IGUIConstants.TILE_EDIT_TREASURE;
776# }
777# if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 &&
778# arch_type == 20 || arch_type == 23 || arch_type == 26 ||
779# arch_type == 91 || arch_type == 21 || arch_type == 24) {
780# // Door: door/special door/gates + keys
781# edit_type |= IGUIConstants.TILE_EDIT_DOOR;
782# }
783# if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 &&
784# getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 &&
785# arch_type <= 16) || arch_type == 33 || arch_type == 34 ||
786# arch_type == 35 || arch_type == 39 || arch_type == 70 ||
787# arch_type == 87 || arch_type == 99 || arch_type == 100 ||
788# arch_type == 104 || arch_type == 109 || arch_type == 113 ||
789# arch_type == 122 || arch_type == 3)) {
790# // Equipment: weapons/armour/wands/rods
791# edit_type |= IGUIConstants.TILE_EDIT_EQUIP;
792# }
793#
794# return(edit_type);
795#
796#
797}
798
799sub cache_file($$&&) { 801sub cache_file($$&&) {
800 my ($src, $cache, $load, $create) = @_; 802 my ($src, $cache, $load, $create) = @_;
801 803
802 my ($size, $mtime) = (stat $src)[7,9] 804 my ($size, $mtime) = (stat $src)[7,9]
803 or Carp::croak "$src: $!"; 805 or Carp::croak "$src: $!";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines