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.121 by root, Mon Apr 14 00:35:17 2008 UTC vs.
Revision 1.135 by root, Tue Nov 3 14:56:58 2009 UTC

1=head1 NAME 1=head1 NAME
2 2
3Deliantra - Deliantra suppport module to read/write archetypes, maps etc. 3Deliantra - Deliantra suppport module to read/write archetypes, maps etc.
4 4
5=over 4
6
5=cut 7=cut
6 8
7package Deliantra; 9package Deliantra;
8 10
9our $VERSION = '1.14'; 11our $VERSION = '1.25';
10 12
11use strict; 13use common::sense;
12 14
13use base 'Exporter'; 15use base 'Exporter';
14 16
15use Carp (); 17use Carp ();
16use File::Spec; 18use File::Spec;
24 editor_archs arch_extents 26 editor_archs arch_extents
25); 27);
26 28
27use JSON::XS qw(decode_json encode_json); 29use JSON::XS qw(decode_json encode_json);
28 30
29our $LIB = $ENV{DELIANTRA_LIBDIR} || $ENV{CROSSFIRE_LIBDIR}; 31our $LIB = $ENV{DELIANTRA_LIBDIR};
30
31our $OLDDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire"
32 : $ENV{AppData} ? "$ENV{APPDATA}/crossfire"
33 : File::Spec->tmpdir . "/crossfire";
34 32
35our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.deliantra" 33our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.deliantra"
36 : $ENV{AppData} ? "$ENV{APPDATA}/deliantra" 34 : $ENV{AppData} ? "$ENV{APPDATA}/deliantra"
37 : File::Spec->tmpdir . "/deliantra"; 35 : File::Spec->tmpdir . "/deliantra";
38 36
73 71
74 elevation 72 elevation
75 73
76 name name_pl custom_name attach title race 74 name name_pl custom_name attach title race
77 slaying skill msg lore other_arch 75 slaying skill msg lore other_arch
78 face animation is_animated 76 sound sound_destroy face animation is_animated
79 magicmap smoothlevel smoothface 77 magicmap smoothlevel smoothface
80 str dex con wis pow cha int 78 str dex con wis pow cha int
81 hp maxhp sp maxsp grace maxgrace 79 hp maxhp sp maxsp grace maxgrace
82 exp perm_exp expmul 80 exp perm_exp expmul
83 food dam luck wc ac x y speed speed_left move_state attack_movement 81 food dam luck wc ac x y speed speed_left move_state attack_movement
155 boat => MOVE_BOAT, 153 boat => MOVE_BOAT,
156 ship => MOVE_SHIP, 154 ship => MOVE_SHIP,
157 all => MOVE_ALL, 155 all => MOVE_ALL,
158); 156);
159 157
160our @MOVE_TYPE = keys %MOVE_TYPE; 158our @MOVE_TYPE = qw(all walk flying fly_low fly_high swim boat ship);
161 159
162{ 160{
163 package Deliantra::MoveType; 161 package Deliantra::MoveType;
164 162
165 use overload 163 use overload
186 $_[0] 184 $_[0]
187 }, 185 },
188 'eq' => sub { "$_[0]" eq "$_[1]" }, 186 'eq' => sub { "$_[0]" eq "$_[1]" },
189 'ne' => sub { "$_[0]" ne "$_[1]" }, 187 'ne' => sub { "$_[0]" ne "$_[1]" },
190 ; 188 ;
189
190 sub TO_JSON {
191 $_[0][0]
192 }
191} 193}
192 194
193sub Deliantra::MoveType::new { 195sub Deliantra::MoveType::new {
194 my ($class, $string) = @_; 196 my ($class, $string) = @_;
195 197
337 339
338# object as in "Object xxx", i.e. archetypes 340# object as in "Object xxx", i.e. archetypes
339sub normalize_object($) { 341sub normalize_object($) {
340 my ($ob) = @_; 342 my ($ob) = @_;
341 343
344 delete $ob->{editable}; # deprecated
345
342 # convert material bitset to materialname, if possible 346 # convert material bitset to materialname, if possible
343 if (exists $ob->{material}) { 347 if (exists $ob->{material}) {
344 if (!$ob->{material}) { 348 if (!$ob->{material}) {
345 delete $ob->{material}; 349 delete $ob->{material};
346 } elsif (exists $ob->{materialname}) { 350 } elsif (exists $ob->{materialname}) {
389 $ob->{$attr} = new Deliantra::MoveType $ob->{$attr}; 393 $ob->{$attr} = new Deliantra::MoveType $ob->{$attr};
390 } 394 }
391 395
392 # convert outdated movement flags to new movement sets 396 # convert outdated movement flags to new movement sets
393 if (defined (my $v = delete $ob->{no_pass})) { 397 if (defined (my $v = delete $ob->{no_pass})) {
394 $ob->{move_block} = new Deliantra::MoveType $v ? "all" : ""; 398 $ob->{move_block} = new Deliantra::MoveType $v ? "all" : "0";
395 } 399 }
396 if (defined (my $v = delete $ob->{slow_move})) { 400 if (defined (my $v = delete $ob->{slow_move})) {
397 $ob->{move_slow} += "walk"; 401 $ob->{move_slow} += "walk";
398 $ob->{move_slow_penalty} = $v; 402 $ob->{move_slow_penalty} = $v;
399 } 403 }
400 if (defined (my $v = delete $ob->{walk_on})) { 404 if (defined (my $v = delete $ob->{walk_on})) {
401 $ob->{move_on} ||= new Deliantra::MoveType; if ($v) { $ob->{move_on} += "walk" } else { $ob->{move_on} -= "walk" } 405 $ob->{move_on} ||= new Deliantra::MoveType; if ($v) { $ob->{move_on} += "walk" } else { $ob->{move_on} -= "walk" }
402 } 406 }
403 if (defined (my $v = delete $ob->{walk_off})) { 407 if (defined (my $v = delete $ob->{walk_off})) {
404 $ob->{move_off} ||= new Deliantra::MoveType; if ($v) { $ob->{move_off} += "walk" } else { $ob->{move_off} -= "walk" } 408 $ob->{move_off} ||= new Deliantra::MoveType; if ($v) { $ob->{move_off} += "walk" } else { $ob->{move_off} -= "walk" }
405 } 409 }
406 if (defined (my $v = delete $ob->{fly_on})) { 410 if (defined (my $v = delete $ob->{fly_on})) {
434# arch as in "arch xxx", ie.. objects 438# arch as in "arch xxx", ie.. objects
435sub normalize_arch($) { 439sub normalize_arch($) {
436 my ($ob) = @_; 440 my ($ob) = @_;
437 441
438 normalize_object $ob; 442 normalize_object $ob;
443
444 return if $ob->{_atype} eq "object";
439 445
440 my $arch = $ARCH{$ob->{_name}} 446 my $arch = $ARCH{$ob->{_name}}
441 or (warn "$ob->{_name}: no such archetype", return $ob); 447 or (warn "$ob->{_name}: no such archetype", return $ob);
442 448
443 if ($arch->{type} == 22) { # map 449 if ($arch->{type} == 22) { # map
518 524
519 my %arc; 525 my %arc;
520 my ($more, $prev); 526 my ($more, $prev);
521 my $comment; 527 my $comment;
522 528
523 open my $fh, "<:raw:perlio:utf8", $path 529 open my $fh, "<:utf8", $path
524 or Carp::croak "$path: $!"; 530 or Carp::croak "$path: $!";
525 531
526# binmode $fh; 532# binmode $fh;
527 533
528 my $parse_block; $parse_block = sub { 534 my $parse_block; $parse_block = sub {
985 991
986 \%cache 992 \%cache
987 }; 993 };
988} 994}
989 995
996=back
997
990=head1 AUTHOR 998=head1 AUTHOR
991 999
992 Marc Lehmann <schmorp@schmorp.de> 1000 Marc Lehmann <schmorp@schmorp.de>
993 http://home.schmorp.de/ 1001 http://home.schmorp.de/
994 1002

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines