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.73 by root, Tue Sep 12 02:18:06 2006 UTC vs.
Revision 1.88 by root, Sun Feb 18 20:20:58 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '0.9'; 9our $VERSION = '0.96';
10 10
11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
33 JSON::Syck::Dump $_[0] 33 JSON::Syck::Dump $_[0]
34} 34}
35 35
36our $LIB = $ENV{CROSSFIRE_LIBDIR}; 36our $LIB = $ENV{CROSSFIRE_LIBDIR};
37 37
38our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; 38our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire"
39 : $ENV{AppData} ? "$ENV{APPDATA}/crossfire"
40 : File::Spec->tmpdir . "/crossfire";
39 41
40mkdir $VARDIR, 0777; 42mkdir $VARDIR, 0777;
41 43
42sub TILESIZE (){ 32 } 44sub TILESIZE (){ 32 }
43 45
56 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);
57 59
58# same as in server save routine, to (hopefully) be compatible 60# same as in server save routine, to (hopefully) be compatible
59# to the other editors. 61# to the other editors.
60our @FIELD_ORDER_MAP = (qw( 62our @FIELD_ORDER_MAP = (qw(
63 file_format_version
61 name attach swap_time reset_timeout fixed_resettime difficulty region 64 name attach swap_time reset_timeout fixed_resettime difficulty region
62 shopitems shopgreed shopmin shopmax shoprace 65 shopitems shopgreed shopmin shopmax shoprace
63 darkness width height enter_x enter_y msg maplore 66 darkness width height enter_x enter_y msg maplore
64 unique template 67 unique template
65 outdoor temp pressure humid windspeed winddir sky nosmooth 68 outdoor temp pressure humid windspeed winddir sky nosmooth
197 while (my ($k, $v) = each %attack_mask) { 200 while (my ($k, $v) = each %attack_mask) {
198 $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;
199 } 202 }
200} 203}
201 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
202# object as in "Object xxx", i.e. archetypes 236# object as in "Object xxx", i.e. archetypes
203sub normalize_object($) { 237sub normalize_object($) {
204 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 }
205 258
206 # nuke outdated or never supported fields 259 # nuke outdated or never supported fields
207 delete @$ob{qw( 260 delete @$ob{qw(
208 can_knockback can_parry can_impale can_cut can_dam_armour 261 can_knockback can_parry can_impale can_cut can_dam_armour
209 can_apply pass_thru can_pass_thru 262 can_apply pass_thru can_pass_thru
252 if (defined (my $v = delete $ob->{slow_move})) { 305 if (defined (my $v = delete $ob->{slow_move})) {
253 $ob->{move_slow} |= MOVE_WALK; 306 $ob->{move_slow} |= MOVE_WALK;
254 $ob->{move_slow_penalty} = $v; 307 $ob->{move_slow_penalty} = $v;
255 } 308 }
256 if (defined (my $v = delete $ob->{walk_on})) { 309 if (defined (my $v = delete $ob->{walk_on})) {
257 $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; 310 $ob->{move_on} = MOVE_NONE unless exists $ob->{move_on};
258 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK 311 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK
259 : $ob->{move_on} & ~MOVE_WALK; 312 : $ob->{move_on} & ~MOVE_WALK;
260 } 313 }
261 if (defined (my $v = delete $ob->{walk_off})) { 314 if (defined (my $v = delete $ob->{walk_off})) {
262 $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; 315 $ob->{move_off} = MOVE_NONE unless exists $ob->{move_off};
263 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK 316 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK
264 : $ob->{move_off} & ~MOVE_WALK; 317 : $ob->{move_off} & ~MOVE_WALK;
265 } 318 }
266 if (defined (my $v = delete $ob->{fly_on})) { 319 if (defined (my $v = delete $ob->{fly_on})) {
267 $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; 320 $ob->{move_on} = MOVE_NONE unless exists $ob->{move_on};
268 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW 321 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW
269 : $ob->{move_on} & ~MOVE_FLY_LOW; 322 : $ob->{move_on} & ~MOVE_FLY_LOW;
270 } 323 }
271 if (defined (my $v = delete $ob->{fly_off})) { 324 if (defined (my $v = delete $ob->{fly_off})) {
272 $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; 325 $ob->{move_off} = MOVE_NONE unless exists $ob->{move_off};
273 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW 326 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW
274 : $ob->{move_off} & ~MOVE_FLY_LOW; 327 : $ob->{move_off} & ~MOVE_FLY_LOW;
275 } 328 }
276 if (defined (my $v = delete $ob->{flying})) { 329 if (defined (my $v = delete $ob->{flying})) {
277 $ob->{move_type} = MOVE_ALL unless exists $ob->{move_type}; 330 $ob->{move_type} = MOVE_NONE unless exists $ob->{move_type};
278 $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW 331 $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW
279 : $ob->{move_type} & ~MOVE_FLY_LOW; 332 : $ob->{move_type} & ~MOVE_FLY_LOW;
280 } 333 }
281 334
282 # convert idiotic event_xxx things into objects 335 # convert idiotic event_xxx things into objects
382sub read_arch($;$) { 435sub read_arch($;$) {
383 my ($path, $toplevel) = @_; 436 my ($path, $toplevel) = @_;
384 437
385 my %arc; 438 my %arc;
386 my ($more, $prev); 439 my ($more, $prev);
440 my $comment;
387 441
388 open my $fh, "<:raw:perlio:utf8", $path 442 open my $fh, "<:raw:perlio:utf8", $path
389 or Carp::croak "$path: $!"; 443 or Carp::croak "$path: $!";
390 444
391# binmode $fh; 445# binmode $fh;
395 449
396 while (<$fh>) { 450 while (<$fh>) {
397 s/\s+$//; 451 s/\s+$//;
398 if (/^end$/i) { 452 if (/^end$/i) {
399 last; 453 last;
454
400 } elsif (/^arch (\S+)$/i) { 455 } elsif (/^arch (\S+)$/i) {
401 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); 456 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
457
402 } elsif (/^lore$/i) { 458 } elsif (/^lore$/i) {
403 while (<$fh>) { 459 while (<$fh>) {
404 last if /^endlore\s*$/i; 460 last if /^endlore\s*$/i;
405 $arc{lore} .= $_; 461 $arc{lore} .= $_;
406 } 462 }
415 chomp; 471 chomp;
416 push @{ $arc{anim} }, $_; 472 push @{ $arc{anim} }, $_;
417 } 473 }
418 } elsif (/^(\S+)\s*(.*)$/) { 474 } elsif (/^(\S+)\s*(.*)$/) {
419 $arc{lc $1} = $2; 475 $arc{lc $1} = $2;
420 } elsif (/^\s*($|#)/) { 476 } elsif (/^\s*#/) {
477 $arc{_comment} .= "$_\n";
478
479 } elsif (/^\s*$/) {
421 # 480 #
422 } else { 481 } else {
423 warn "$path: unparsable line '$_' in arch $arc{_name}"; 482 warn "$path: unparsable line '$_' in arch $arc{_name}";
424 } 483 }
425 } 484 }
431 s/\s+$//; 490 s/\s+$//;
432 if (/^more$/i) { 491 if (/^more$/i) {
433 $more = $prev; 492 $more = $prev;
434 } elsif (/^object (\S+)$/i) { 493 } elsif (/^object (\S+)$/i) {
435 my $name = $1; 494 my $name = $1;
436 my $arc = attr_thaw normalize_object $parse_block->(_name => $name); 495 my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment);
496 undef $comment;
497 delete $arc{_comment} unless length $arc{_comment};
437 $arc->{_atype} = 'object'; 498 $arc->{_atype} = 'object';
438 499
439 if ($more) { 500 if ($more) {
440 $more->{more} = $arc; 501 $more->{more} = $arc;
441 } else { 502 } else {
443 } 504 }
444 $prev = $arc; 505 $prev = $arc;
445 $more = undef; 506 $more = undef;
446 } elsif (/^arch (\S+)$/i) { 507 } elsif (/^arch (\S+)$/i) {
447 my $name = $1; 508 my $name = $1;
448 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); 509 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment);
510 undef $comment;
511 delete $arc{_comment} unless length $arc{_comment};
449 $arc->{_atype} = 'arch'; 512 $arc->{_atype} = 'arch';
450 513
451 if ($more) { 514 if ($more) {
452 $more->{more} = $arc; 515 $more->{more} = $arc;
453 } else { 516 } else {
462 push @{$toplevel->{lev_array}}, $_+0; 525 push @{$toplevel->{lev_array}}, $_+0;
463 } 526 }
464 } else { 527 } else {
465 $toplevel->{$1} = $2; 528 $toplevel->{$1} = $2;
466 } 529 }
530 } elsif (/^\s*#/) {
531 $comment .= "$_\n";
467 } elsif (/^\s*($|#)/) { 532 } elsif (/^\s*($|#)/) {
468 # 533 #
469 } else { 534 } else {
470 die "$path: unparseable top-level line '$_'"; 535 die "$path: unparseable top-level line '$_'";
471 } 536 }
491 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}) {
492 $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) 557 $a{attack_movement} = (delete $a{attack_movement_bits_0_3})
493 | (delete $a{attack_movement_bits_4_7}); 558 | (delete $a{attack_movement_bits_4_7});
494 } 559 }
495 560
561 if (my $comment = delete $a{_comment}) {
562 if ($comment =~ /[^\n\s#]/) {
563 $str .= $comment;
564 }
565 }
566
496 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; 567 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n";
497 568
498 my $inv = delete $a{inventory}; 569 my $inv = delete $a{inventory};
499 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
500 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 }
501 577
502 my @kv; 578 my @kv;
503 579
504 for ($a{_name} eq "map" 580 for ($a{_name} eq "map"
505 ? @Crossfire::FIELD_ORDER_MAP 581 ? @Crossfire::FIELD_ORDER_MAP
552 628
553 if ($inv) { 629 if ($inv) {
554 $append->($_) for @$inv; 630 $append->($_) for @$inv;
555 } 631 }
556 632
633 $str .= "end\n";
634
557 if ($a{_atype} eq 'object') { 635 if ($a{_atype} eq 'object') {
558 $str .= join "\n", "anim", @$anim, "mina\n" 636 if ($more) {
559 if $anim;
560 }
561
562 $str .= "end\n";
563
564 if (($a{_atype} eq 'object') && $more) {
565 $str .= "\nmore\n"; 637 $str .= "more\n";
566 $append->($more) if $more; 638 $append->($more) if $more;
639 } else {
640 $str .= "\n";
641 }
567 } 642 }
568 }; 643 };
569 644
570 for (@$arch) { 645 for (@$arch) {
571 $append->($_); 646 $append->($_);
600 my ($a) = @_; 675 my ($a) = @_;
601 676
602 my $o = $ARCH{$a->{_name}} 677 my $o = $ARCH{$a->{_name}}
603 or return; 678 or return;
604 679
605 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} 680 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"};
681 unless ($face) {
682 $face = $FACE{"blank.x11"}
606 or (warn "no face data found for arch '$a->{_name}'"), return; 683 or (warn "no face data found for arch '$a->{_name}'"), return;
684 }
607 685
608 if ($face->{w} > 1 || $face->{h} > 1) { 686 if ($face->{w} > 1 || $face->{h} > 1) {
609 # bigface 687 # bigface
610 return (0, 0, $face->{w} - 1, $face->{h} - 1); 688 return (0, 0, $face->{w} - 1, $face->{h} - 1);
611 689
718 ]; 796 ];
719 797
720 $attr 798 $attr
721} 799}
722 800
723sub arch_edit_sections {
724# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
725# edit_type = 0;
726# else if (edit_type != 0) {
727# // all flags from 'check_type' must be unset in this arch because they get recalculated now
728# edit_type &= ~check_type;
729# }
730#
731# }
732# if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 &&
733# getAttributeValue("alive", defarch) == 1 &&
734# (getAttributeValue("monster", defarch) == 1 ||
735# getAttributeValue("generator", defarch) == 1)) {
736# // Monster: monsters/npcs/generators
737# edit_type |= IGUIConstants.TILE_EDIT_MONSTER;
738# }
739# if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 &&
740# arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) {
741# // Walls
742# edit_type |= IGUIConstants.TILE_EDIT_WALL;
743# }
744# if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 &&
745# getAttributeValue("connected", defarch) != 0) {
746# // Connected Objects
747# edit_type |= IGUIConstants.TILE_EDIT_CONNECTED;
748# }
749# if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 &&
750# arch_type == 66 || arch_type == 41 || arch_type == 95) {
751# // Exit: teleporter/exit/trapdoors
752# edit_type |= IGUIConstants.TILE_EDIT_EXIT;
753# }
754# if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 &&
755# getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 ||
756# arch_type == 5 || arch_type == 36 || arch_type == 60 ||
757# arch_type == 85 || arch_type == 111 || arch_type == 123 ||
758# arch_type == 124 || arch_type == 130)) {
759# // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls
760# edit_type |= IGUIConstants.TILE_EDIT_TREASURE;
761# }
762# if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 &&
763# arch_type == 20 || arch_type == 23 || arch_type == 26 ||
764# arch_type == 91 || arch_type == 21 || arch_type == 24) {
765# // Door: door/special door/gates + keys
766# edit_type |= IGUIConstants.TILE_EDIT_DOOR;
767# }
768# if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 &&
769# getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 &&
770# arch_type <= 16) || arch_type == 33 || arch_type == 34 ||
771# arch_type == 35 || arch_type == 39 || arch_type == 70 ||
772# arch_type == 87 || arch_type == 99 || arch_type == 100 ||
773# arch_type == 104 || arch_type == 109 || arch_type == 113 ||
774# arch_type == 122 || arch_type == 3)) {
775# // Equipment: weapons/armour/wands/rods
776# edit_type |= IGUIConstants.TILE_EDIT_EQUIP;
777# }
778#
779# return(edit_type);
780#
781#
782}
783
784sub cache_file($$&&) { 801sub cache_file($$&&) {
785 my ($src, $cache, $load, $create) = @_; 802 my ($src, $cache, $load, $create) = @_;
786 803
787 my ($size, $mtime) = (stat $src)[7,9] 804 my ($size, $mtime) = (stat $src)[7,9]
788 or Carp::croak "$src: $!"; 805 or Carp::croak "$src: $!";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines