… | |
… | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
|
|
17 | use File::Spec; |
16 | use File::Spec; |
18 | use List::Util qw(min max); |
17 | use List::Util qw(min max); |
19 | |
18 | |
20 | #XXX: The map_* procedures scream for a map-object |
19 | #XXX: The map_* procedures scream for a map-object |
21 | |
20 | |
… | |
… | |
45 | sub MOVE_FLY_HIGH (){ 0x4 } |
44 | sub MOVE_FLY_HIGH (){ 0x4 } |
46 | sub MOVE_FLYING (){ 0x6 } |
45 | sub MOVE_FLYING (){ 0x6 } |
47 | sub MOVE_SWIM (){ 0x8 } |
46 | sub MOVE_SWIM (){ 0x8 } |
48 | sub MOVE_ALL (){ 0xf } |
47 | sub MOVE_ALL (){ 0xf } |
49 | |
48 | |
|
|
49 | BEGIN { |
|
|
50 | if ($^O eq "MSWin32") { |
|
|
51 | eval "use FreezeThaw qw(freeze thaw)"; |
|
|
52 | } else { |
|
|
53 | eval "use Storable qw(freeze thaw)"; |
|
|
54 | } |
|
|
55 | } |
|
|
56 | |
50 | sub load_ref($) { |
57 | sub load_ref($) { |
51 | my ($path) = @_; |
58 | my ($path) = @_; |
52 | |
59 | |
|
|
60 | open my $fh, "<:raw", "$path~" |
|
|
61 | or die "$path~: $!"; |
|
|
62 | local $/; |
|
|
63 | thaw <$fh> |
|
|
64 | } |
|
|
65 | |
|
|
66 | sub save_ref($$) { |
|
|
67 | my ($ref, $path) = @_; |
|
|
68 | |
53 | open my $fh, ">:raw", "$path~" |
69 | open my $fh, ">:raw", "$path~" |
54 | or die "$path~: $!"; |
70 | or die "$path~: $!"; |
55 | local $/; |
71 | my $ref = freeze $ref; |
56 | Storable::thaw <$fh> |
72 | print $fh $ref; |
57 | } |
|
|
58 | |
|
|
59 | sub save_ref($$) { |
|
|
60 | my ($ref, $path) = @_; |
|
|
61 | |
|
|
62 | open my $fh, ">:raw", "$path~" |
|
|
63 | or die "$path~: $!"; |
|
|
64 | print $fh Storable::nfreeze $ref; |
|
|
65 | close $fh; |
73 | close $fh; |
66 | rename "$path~", $path |
74 | rename "$path~", $path |
67 | or die "$path: $!"; |
75 | or die "$path: $!"; |
68 | } |
76 | } |
69 | |
77 | |
… | |
… | |
399 | |
407 | |
400 | mkdir $cachedir, 0777; |
408 | mkdir $cachedir, 0777; |
401 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
409 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
402 | } |
410 | } |
403 | |
411 | |
404 | $VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; |
412 | $VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; |
405 | |
413 | |
406 | init $VARDIR; |
414 | init $VARDIR; |
407 | |
415 | |
408 | =head1 AUTHOR |
416 | =head1 AUTHOR |
409 | |
417 | |