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.72 by root, Mon Sep 4 17:58:51 2006 UTC vs.
Revision 1.86 by root, Wed Feb 7 00:56:06 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
193 196
194sub _add_resist($$$) { 197sub _add_resist($$$) {
195 my ($ob, $mask, $value) = @_; 198 my ($ob, $mask, $value) = @_;
196 199
197 while (my ($k, $v) = each %attack_mask) { 200 while (my ($k, $v) = each %attack_mask) {
198 $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}
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;
201 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
288 slaying => delete $ob->{"event_${event}"}, 341 slaying => delete $ob->{"event_${event}"},
289 name => delete $ob->{"event_${event}_options"}, 342 name => delete $ob->{"event_${event}_options"},
290 }; 343 };
291 } 344 }
292 } 345 }
346
347 # some archetypes had "+3" instead of the canonical "3", so fix
348 $ob->{dam} *= 1 if exists $ob->{dam};
293 349
294 $ob 350 $ob
295} 351}
296 352
297# arch as in "arch xxx", ie.. objects 353# arch as in "arch xxx", ie.. objects
379sub read_arch($;$) { 435sub read_arch($;$) {
380 my ($path, $toplevel) = @_; 436 my ($path, $toplevel) = @_;
381 437
382 my %arc; 438 my %arc;
383 my ($more, $prev); 439 my ($more, $prev);
440 my $comment;
384 441
385 open my $fh, "<:raw:perlio:utf8", $path 442 open my $fh, "<:raw:perlio:utf8", $path
386 or Carp::croak "$path: $!"; 443 or Carp::croak "$path: $!";
387 444
388# binmode $fh; 445# binmode $fh;
392 449
393 while (<$fh>) { 450 while (<$fh>) {
394 s/\s+$//; 451 s/\s+$//;
395 if (/^end$/i) { 452 if (/^end$/i) {
396 last; 453 last;
454
397 } elsif (/^arch (\S+)$/i) { 455 } elsif (/^arch (\S+)$/i) {
398 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); 456 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
457
399 } elsif (/^lore$/i) { 458 } elsif (/^lore$/i) {
400 while (<$fh>) { 459 while (<$fh>) {
401 last if /^endlore\s*$/i; 460 last if /^endlore\s*$/i;
402 $arc{lore} .= $_; 461 $arc{lore} .= $_;
403 } 462 }
412 chomp; 471 chomp;
413 push @{ $arc{anim} }, $_; 472 push @{ $arc{anim} }, $_;
414 } 473 }
415 } elsif (/^(\S+)\s*(.*)$/) { 474 } elsif (/^(\S+)\s*(.*)$/) {
416 $arc{lc $1} = $2; 475 $arc{lc $1} = $2;
417 } elsif (/^\s*($|#)/) { 476 } elsif (/^\s*#/) {
477 $arc{_comment} .= "$_\n";
478
479 } elsif (/^\s*$/) {
418 # 480 #
419 } else { 481 } else {
420 warn "$path: unparsable line '$_' in arch $arc{_name}"; 482 warn "$path: unparsable line '$_' in arch $arc{_name}";
421 } 483 }
422 } 484 }
428 s/\s+$//; 490 s/\s+$//;
429 if (/^more$/i) { 491 if (/^more$/i) {
430 $more = $prev; 492 $more = $prev;
431 } elsif (/^object (\S+)$/i) { 493 } elsif (/^object (\S+)$/i) {
432 my $name = $1; 494 my $name = $1;
433 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};
434 $arc->{_atype} = 'object'; 498 $arc->{_atype} = 'object';
435 499
436 if ($more) { 500 if ($more) {
437 $more->{more} = $arc; 501 $more->{more} = $arc;
438 } else { 502 } else {
440 } 504 }
441 $prev = $arc; 505 $prev = $arc;
442 $more = undef; 506 $more = undef;
443 } elsif (/^arch (\S+)$/i) { 507 } elsif (/^arch (\S+)$/i) {
444 my $name = $1; 508 my $name = $1;
445 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};
446 $arc->{_atype} = 'arch'; 512 $arc->{_atype} = 'arch';
447 513
448 if ($more) { 514 if ($more) {
449 $more->{more} = $arc; 515 $more->{more} = $arc;
450 } else { 516 } else {
459 push @{$toplevel->{lev_array}}, $_+0; 525 push @{$toplevel->{lev_array}}, $_+0;
460 } 526 }
461 } else { 527 } else {
462 $toplevel->{$1} = $2; 528 $toplevel->{$1} = $2;
463 } 529 }
530 } elsif (/^\s*#/) {
531 $comment .= "$_\n";
464 } elsif (/^\s*($|#)/) { 532 } elsif (/^\s*($|#)/) {
465 # 533 #
466 } else { 534 } else {
467 die "$path: unparseable top-level line '$_'"; 535 die "$path: unparseable top-level line '$_'";
468 } 536 }
488 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}) {
489 $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) 557 $a{attack_movement} = (delete $a{attack_movement_bits_0_3})
490 | (delete $a{attack_movement_bits_4_7}); 558 | (delete $a{attack_movement_bits_4_7});
491 } 559 }
492 560
561 if (my $comment = delete $a{_comment}) {
562 if ($comment =~ /[^\n\s#]/) {
563 $str .= $comment;
564 }
565 }
566
493 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; 567 $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n";
494 568
495 my $inv = delete $a{inventory}; 569 my $inv = delete $a{inventory};
496 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
497 my $anim = delete $a{anim}; 571 my $anim = delete $a{anim};
498 572
499 my @kv; 573 my @kv;
500 574
556 if $anim; 630 if $anim;
557 } 631 }
558 632
559 $str .= "end\n"; 633 $str .= "end\n";
560 634
561 if (($a{_atype} eq 'object') && $more) { 635 if ($a{_atype} eq 'object') {
636 if ($more) {
562 $str .= "\nmore\n"; 637 $str .= "more\n";
563 $append->($more) if $more; 638 $append->($more) if $more;
639 } else {
640 $str .= "\n";
641 }
564 } 642 }
565 }; 643 };
566 644
567 for (@$arch) { 645 for (@$arch) {
568 $append->($_); 646 $append->($_);
597 my ($a) = @_; 675 my ($a) = @_;
598 676
599 my $o = $ARCH{$a->{_name}} 677 my $o = $ARCH{$a->{_name}}
600 or return; 678 or return;
601 679
602 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"}
603 or (warn "no face data found for arch '$a->{_name}'"), return; 683 or (warn "no face data found for arch '$a->{_name}'"), return;
684 }
604 685
605 if ($face->{w} > 1 || $face->{h} > 1) { 686 if ($face->{w} > 1 || $face->{h} > 1) {
606 # bigface 687 # bigface
607 return (0, 0, $face->{w} - 1, $face->{h} - 1); 688 return (0, 0, $face->{w} - 1, $face->{h} - 1);
608 689

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines