1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | Crossfire - Crossfire maphandling |
3 | Deliantra - Deliantra suppport module to read/write archetypes, maps etc. |
|
|
4 | |
|
|
5 | =over 4 |
4 | |
6 | |
5 | =cut |
7 | =cut |
6 | |
8 | |
7 | package Crossfire; |
9 | package Deliantra; |
8 | |
10 | |
9 | our $VERSION = '0.98'; |
11 | our $VERSION = '1.25'; |
10 | |
12 | |
11 | use strict; |
13 | use common::sense; |
12 | |
14 | |
13 | use base 'Exporter'; |
15 | use base 'Exporter'; |
14 | |
16 | |
15 | use Carp (); |
17 | use Carp (); |
16 | use File::Spec; |
18 | use File::Spec; |
17 | use List::Util qw(min max); |
19 | use List::Util qw(min max); |
18 | use Storable qw(freeze thaw); |
20 | use Storable qw(freeze thaw); |
19 | |
21 | |
20 | our @EXPORT = qw( |
22 | our @EXPORT = qw( |
21 | read_pak read_arch *ARCH TILESIZE $TILE *FACE editor_archs arch_extents |
23 | read_pak read_arch |
|
|
24 | *ARCH $TILE *FACE *FACEDATA |
|
|
25 | TILESIZE CACHESTRIDE |
|
|
26 | editor_archs arch_extents |
22 | ); |
27 | ); |
23 | |
28 | |
24 | use JSON::XS qw(from_json to_json); |
29 | use JSON::XS qw(decode_json encode_json); |
25 | |
30 | |
26 | our $LIB = $ENV{CROSSFIRE_LIBDIR}; |
31 | our $LIB = $ENV{DELIANTRA_LIBDIR}; |
27 | |
32 | |
28 | our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" |
33 | our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.deliantra" |
29 | : $ENV{AppData} ? "$ENV{APPDATA}/crossfire" |
34 | : $ENV{AppData} ? "$ENV{APPDATA}/deliantra" |
30 | : File::Spec->tmpdir . "/crossfire"; |
35 | : File::Spec->tmpdir . "/deliantra"; |
31 | |
36 | |
32 | mkdir $VARDIR, 0777; |
37 | mkdir $VARDIR, 0777; |
33 | |
38 | |
34 | sub TILESIZE (){ 32 } |
39 | sub TILESIZE (){ 32 } |
|
|
40 | sub CACHESTRIDE (){ 64 } |
35 | |
41 | |
36 | our %ARCH; |
42 | our %ARCH; |
|
|
43 | our %FACE; # face32 |
37 | our %FACE; |
44 | our %FACEDATA; |
38 | our $TILE; |
45 | our $TILE; |
39 | |
46 | |
40 | our %FIELD_MULTILINE = ( |
47 | our %FIELD_MULTILINE = ( |
41 | msg => "endmsg", |
48 | msg => "endmsg", |
42 | lore => "endlore", |
49 | lore => "endlore", |
… | |
… | |
64 | |
71 | |
65 | elevation |
72 | elevation |
66 | |
73 | |
67 | name name_pl custom_name attach title race |
74 | name name_pl custom_name attach title race |
68 | slaying skill msg lore other_arch |
75 | slaying skill msg lore other_arch |
69 | face animation is_animated |
76 | sound sound_destroy face animation is_animated |
70 | magicmap smoothlevel smoothface |
77 | magicmap smoothlevel smoothface |
71 | str dex con wis pow cha int |
78 | str dex con wis pow cha int |
72 | hp maxhp sp maxsp grace maxgrace |
79 | hp maxhp sp maxsp grace maxgrace |
73 | exp perm_exp expmul |
80 | exp perm_exp expmul |
74 | 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 |
… | |
… | |
146 | boat => MOVE_BOAT, |
153 | boat => MOVE_BOAT, |
147 | ship => MOVE_SHIP, |
154 | ship => MOVE_SHIP, |
148 | all => MOVE_ALL, |
155 | all => MOVE_ALL, |
149 | ); |
156 | ); |
150 | |
157 | |
151 | our @MOVE_TYPE = keys %MOVE_TYPE; |
158 | our @MOVE_TYPE = qw(all walk flying fly_low fly_high swim boat ship); |
152 | |
159 | |
153 | { |
160 | { |
154 | package Crossfire::MoveType; |
161 | package Deliantra::MoveType; |
155 | |
162 | |
156 | use overload |
163 | use overload |
157 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
164 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
158 | '""' => \&as_string, |
165 | '""' => \&as_string, |
159 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
166 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
… | |
… | |
177 | $_[0] |
184 | $_[0] |
178 | }, |
185 | }, |
179 | 'eq' => sub { "$_[0]" eq "$_[1]" }, |
186 | 'eq' => sub { "$_[0]" eq "$_[1]" }, |
180 | 'ne' => sub { "$_[0]" ne "$_[1]" }, |
187 | 'ne' => sub { "$_[0]" ne "$_[1]" }, |
181 | ; |
188 | ; |
182 | } |
|
|
183 | |
189 | |
184 | sub Crossfire::MoveType::new { |
190 | sub TO_JSON { |
|
|
191 | $_[0][0] |
|
|
192 | } |
|
|
193 | } |
|
|
194 | |
|
|
195 | sub Deliantra::MoveType::new { |
185 | my ($class, $string) = @_; |
196 | my ($class, $string) = @_; |
186 | |
197 | |
187 | my $mask; |
198 | my $mask; |
188 | my $value; |
199 | my $value; |
189 | |
200 | |
… | |
… | |
203 | } |
214 | } |
204 | |
215 | |
205 | (bless [$mask, $value], $class)->normalise |
216 | (bless [$mask, $value], $class)->normalise |
206 | } |
217 | } |
207 | |
218 | |
208 | sub Crossfire::MoveType::normalise { |
219 | sub Deliantra::MoveType::normalise { |
209 | my ($self) = @_; |
220 | my ($self) = @_; |
210 | |
221 | |
211 | if ($self->[0] & MOVE_ALL) { |
222 | if ($self->[0] & MOVE_ALL) { |
212 | my $mask = ~(($self->[1] & MOVE_ALL ? $self->[1] : ~$self->[1]) & $self->[0] & ~MOVE_ALL); |
223 | my $mask = ~(($self->[1] & MOVE_ALL ? $self->[1] : ~$self->[1]) & $self->[0] & ~MOVE_ALL); |
213 | $self->[0] &= $mask; |
224 | $self->[0] &= $mask; |
… | |
… | |
217 | $self->[1] &= $self->[0]; |
228 | $self->[1] &= $self->[0]; |
218 | |
229 | |
219 | $self |
230 | $self |
220 | } |
231 | } |
221 | |
232 | |
222 | sub Crossfire::MoveType::as_string { |
233 | sub Deliantra::MoveType::as_string { |
223 | my ($self) = @_; |
234 | my ($self) = @_; |
224 | |
235 | |
225 | my @res; |
236 | my @res; |
226 | |
237 | |
227 | my ($mask, $value) = @$self; |
238 | my ($mask, $value) = @$self; |
228 | |
239 | |
229 | for (@Crossfire::MOVE_TYPE) { |
240 | for (@Deliantra::MOVE_TYPE) { |
230 | my $bit = $Crossfire::MOVE_TYPE{$_}; |
241 | my $bit = $Deliantra::MOVE_TYPE{$_}; |
231 | if (($mask & $bit) == $bit && (($value & $bit) == $bit || ($value & $bit) == 0)) { |
242 | if (($mask & $bit) == $bit && (($value & $bit) == $bit || ($value & $bit) == 0)) { |
232 | $mask &= ~$bit; |
243 | $mask &= ~$bit; |
233 | push @res, $value & $bit ? $_ : "-$_"; |
244 | push @res, $value & $bit ? $_ : "-$_"; |
234 | } |
245 | } |
235 | } |
246 | } |
… | |
… | |
352 | # check whether attachment is the same as in the archetype |
363 | # check whether attachment is the same as in the archetype |
353 | if (exists $ob->{attach}) { |
364 | if (exists $ob->{attach}) { |
354 | my $arch = $ARCH{$ob->{_name}}; |
365 | my $arch = $ARCH{$ob->{_name}}; |
355 | my $js = JSON::XS->new->utf8->canonical (1); |
366 | my $js = JSON::XS->new->utf8->canonical (1); |
356 | |
367 | |
|
|
368 | if (defined $arch->{attach} |
357 | if ($js->encode ($js->decode ($ob->{attach})) eq $js->encode ($arch->{attach})) { |
369 | && $js->encode ($js->decode ($ob->{attach})) eq $js->encode ($arch->{attach})) { |
358 | delete $ob->{attach} |
370 | delete $ob->{attach} |
359 | } |
371 | } |
360 | } |
372 | } |
361 | |
373 | |
362 | # color_fg is used as default for magicmap if magicmap does not exist |
374 | # color_fg is used as default for magicmap if magicmap does not exist |
… | |
… | |
374 | |
386 | |
375 | # convert movement strings to bitsets |
387 | # convert movement strings to bitsets |
376 | for my $attr (keys %FIELD_MOVEMENT) { |
388 | for my $attr (keys %FIELD_MOVEMENT) { |
377 | next unless exists $ob->{$attr}; |
389 | next unless exists $ob->{$attr}; |
378 | |
390 | |
379 | $ob->{$attr} = new Crossfire::MoveType $ob->{$attr}; |
391 | $ob->{$attr} = new Deliantra::MoveType $ob->{$attr}; |
380 | } |
392 | } |
381 | |
393 | |
382 | # convert outdated movement flags to new movement sets |
394 | # convert outdated movement flags to new movement sets |
383 | if (defined (my $v = delete $ob->{no_pass})) { |
395 | if (defined (my $v = delete $ob->{no_pass})) { |
384 | $ob->{move_block} = new Crossfire::MoveType $v ? "all" : ""; |
396 | $ob->{move_block} = new Deliantra::MoveType $v ? "all" : "0"; |
385 | } |
397 | } |
386 | if (defined (my $v = delete $ob->{slow_move})) { |
398 | if (defined (my $v = delete $ob->{slow_move})) { |
387 | $ob->{move_slow} += "walk"; |
399 | $ob->{move_slow} += "walk"; |
388 | $ob->{move_slow_penalty} = $v; |
400 | $ob->{move_slow_penalty} = $v; |
389 | } |
401 | } |
390 | if (defined (my $v = delete $ob->{walk_on})) { |
402 | if (defined (my $v = delete $ob->{walk_on})) { |
391 | $ob->{move_on} ||= new Crossfire::MoveType; if ($v) { $ob->{move_on} += "walk" } else { $ob->{move_on} -= "walk" } |
403 | $ob->{move_on} ||= new Deliantra::MoveType; if ($v) { $ob->{move_on} += "walk" } else { $ob->{move_on} -= "walk" } |
392 | } |
404 | } |
393 | if (defined (my $v = delete $ob->{walk_off})) { |
405 | if (defined (my $v = delete $ob->{walk_off})) { |
394 | $ob->{move_off} ||= new Crossfire::MoveType; if ($v) { $ob->{move_off} += "walk" } else { $ob->{move_off} -= "walk" } |
406 | $ob->{move_off} ||= new Deliantra::MoveType; if ($v) { $ob->{move_off} += "walk" } else { $ob->{move_off} -= "walk" } |
395 | } |
407 | } |
396 | if (defined (my $v = delete $ob->{fly_on})) { |
408 | if (defined (my $v = delete $ob->{fly_on})) { |
397 | $ob->{move_on} ||= new Crossfire::MoveType; if ($v) { $ob->{move_on} += "fly_low" } else { $ob->{move_on} -= "fly_low" } |
409 | $ob->{move_on} ||= new Deliantra::MoveType; if ($v) { $ob->{move_on} += "fly_low" } else { $ob->{move_on} -= "fly_low" } |
398 | } |
410 | } |
399 | if (defined (my $v = delete $ob->{fly_off})) { |
411 | if (defined (my $v = delete $ob->{fly_off})) { |
400 | $ob->{move_off} ||= new Crossfire::MoveType; if ($v) { $ob->{move_off} += "fly_low" } else { $ob->{move_off} -= "fly_low" } |
412 | $ob->{move_off} ||= new Deliantra::MoveType; if ($v) { $ob->{move_off} += "fly_low" } else { $ob->{move_off} -= "fly_low" } |
401 | } |
413 | } |
402 | if (defined (my $v = delete $ob->{flying})) { |
414 | if (defined (my $v = delete $ob->{flying})) { |
403 | $ob->{move_type} ||= new Crossfire::MoveType; if ($v) { $ob->{move_type} += "fly_low" } else { $ob->{move_type} -= "fly_low" } |
415 | $ob->{move_type} ||= new Deliantra::MoveType; if ($v) { $ob->{move_type} += "fly_low" } else { $ob->{move_type} -= "fly_low" } |
404 | } |
416 | } |
405 | |
417 | |
406 | # convert idiotic event_xxx things into objects |
418 | # convert idiotic event_xxx things into objects |
407 | while (my ($event, $subtype) = each %EVENT_TYPE) { |
419 | while (my ($event, $subtype) = each %EVENT_TYPE) { |
408 | if (exists $ob->{"event_${event}_plugin"}) { |
420 | if (exists $ob->{"event_${event}_plugin"}) { |
… | |
… | |
424 | # arch as in "arch xxx", ie.. objects |
436 | # arch as in "arch xxx", ie.. objects |
425 | sub normalize_arch($) { |
437 | sub normalize_arch($) { |
426 | my ($ob) = @_; |
438 | my ($ob) = @_; |
427 | |
439 | |
428 | normalize_object $ob; |
440 | normalize_object $ob; |
|
|
441 | |
|
|
442 | return if $ob->{_atype} eq "object"; |
429 | |
443 | |
430 | my $arch = $ARCH{$ob->{_name}} |
444 | my $arch = $ARCH{$ob->{_name}} |
431 | or (warn "$ob->{_name}: no such archetype", return $ob); |
445 | or (warn "$ob->{_name}: no such archetype", return $ob); |
432 | |
446 | |
433 | if ($arch->{type} == 22) { # map |
447 | if ($arch->{type} == 22) { # map |
… | |
… | |
469 | } |
483 | } |
470 | |
484 | |
471 | sub attr_thaw($) { |
485 | sub attr_thaw($) { |
472 | my ($ob) = @_; |
486 | my ($ob) = @_; |
473 | |
487 | |
474 | $ob->{attach} = from_json $ob->{attach} |
488 | $ob->{attach} = decode_json $ob->{attach} |
475 | if exists $ob->{attach}; |
489 | if exists $ob->{attach}; |
476 | |
490 | |
477 | $ob |
491 | $ob |
478 | } |
492 | } |
479 | |
493 | |
480 | sub attr_freeze($) { |
494 | sub attr_freeze($) { |
481 | my ($ob) = @_; |
495 | my ($ob) = @_; |
482 | |
496 | |
483 | $ob->{attach} = Crossfire::to_json $ob->{attach} |
497 | $ob->{attach} = JSON::XS->new->utf8->canonical->encode ($ob->{attach}) |
484 | if exists $ob->{attach}; |
498 | if exists $ob->{attach}; |
485 | |
499 | |
486 | $ob |
500 | $ob |
487 | } |
501 | } |
488 | |
502 | |
… | |
… | |
508 | |
522 | |
509 | my %arc; |
523 | my %arc; |
510 | my ($more, $prev); |
524 | my ($more, $prev); |
511 | my $comment; |
525 | my $comment; |
512 | |
526 | |
513 | open my $fh, "<:raw:perlio:utf8", $path |
527 | open my $fh, "<:utf8", $path |
514 | or Carp::croak "$path: $!"; |
528 | or Carp::croak "$path: $!"; |
515 | |
529 | |
516 | # binmode $fh; |
530 | # binmode $fh; |
517 | |
531 | |
518 | my $parse_block; $parse_block = sub { |
532 | my $parse_block; $parse_block = sub { |
… | |
… | |
618 | my $str; |
632 | my $str; |
619 | |
633 | |
620 | my $append; $append = sub { |
634 | my $append; $append = sub { |
621 | my %a = %{$_[0]}; |
635 | my %a = %{$_[0]}; |
622 | |
636 | |
623 | Crossfire::attr_freeze \%a; |
637 | Deliantra::attr_freeze \%a; |
624 | Crossfire::normalize_arch \%a; |
638 | Deliantra::normalize_arch \%a; |
625 | |
639 | |
626 | # undo the bit-split we did before |
640 | # undo the bit-split we did before |
627 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
641 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
628 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
642 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
629 | | (delete $a{attack_movement_bits_4_7}); |
643 | | (delete $a{attack_movement_bits_4_7}); |
… | |
… | |
647 | } |
661 | } |
648 | |
662 | |
649 | my @kv; |
663 | my @kv; |
650 | |
664 | |
651 | for ($a{_name} eq "map" |
665 | for ($a{_name} eq "map" |
652 | ? @Crossfire::FIELD_ORDER_MAP |
666 | ? @Deliantra::FIELD_ORDER_MAP |
653 | : @Crossfire::FIELD_ORDER) { |
667 | : @Deliantra::FIELD_ORDER) { |
654 | push @kv, [$_, delete $a{$_}] |
668 | push @kv, [$_, delete $a{$_}] |
655 | if exists $a{$_}; |
669 | if exists $a{$_}; |
656 | } |
670 | } |
657 | |
671 | |
658 | for (sort keys %a) { |
672 | for (sort keys %a) { |
… | |
… | |
661 | } |
675 | } |
662 | |
676 | |
663 | for (@kv) { |
677 | for (@kv) { |
664 | my ($k, $v) = @$_; |
678 | my ($k, $v) = @$_; |
665 | |
679 | |
666 | if (my $end = $Crossfire::FIELD_MULTILINE{$k}) { |
680 | if (my $end = $Deliantra::FIELD_MULTILINE{$k}) { |
667 | $v =~ s/\n$//; |
681 | $v =~ s/\n$//; |
668 | $str .= "$k\n$v\n$end\n"; |
682 | $str .= "$k\n$v\n$end\n"; |
669 | } else { |
683 | } else { |
670 | $str .= "$k $v\n"; |
684 | $str .= "$k $v\n"; |
671 | } |
685 | } |
… | |
… | |
767 | =cut |
781 | =cut |
768 | |
782 | |
769 | sub arch_attr($) { |
783 | sub arch_attr($) { |
770 | my ($obj) = @_; |
784 | my ($obj) = @_; |
771 | |
785 | |
772 | require Crossfire::Data; |
786 | require Deliantra::Data; |
773 | |
787 | |
774 | my $root; |
788 | my $root; |
775 | my $attr = { }; |
789 | my $attr = { }; |
776 | |
790 | |
777 | my $arch = $ARCH{ $obj->{_name} }; |
791 | my $arch = $ARCH{ $obj->{_name} }; |
778 | my $type = $obj->{type} || $arch->{type}; |
792 | my $type = $obj->{type} || $arch->{type}; |
779 | |
793 | |
780 | if ($type > 0) { |
794 | if ($type > 0) { |
781 | $root = $Crossfire::Data::ATTR{$type}; |
795 | $root = $Deliantra::Data::ATTR{$type}; |
782 | } else { |
796 | } else { |
783 | my %a = (%$arch, %$obj); |
797 | my %a = (%$arch, %$obj); |
784 | |
798 | |
785 | if ($a{is_floor} && !$a{alive}) { |
799 | if ($a{is_floor} && !$a{alive}) { |
786 | $root = $Crossfire::Data::TYPE{Floor}; |
800 | $root = $Deliantra::Data::TYPE{Floor}; |
787 | } elsif (!$a{is_floor} && $a{alive} && !$a{tear_down}) { |
801 | } elsif (!$a{is_floor} && $a{alive} && !$a{tear_down}) { |
788 | $root = $Crossfire::Data::TYPE{"Monster & NPC"}; |
802 | $root = $Deliantra::Data::TYPE{"Monster & NPC"}; |
789 | } elsif (!$a{is_floor} && !$a{alive} && $a{move_block}) { |
803 | } elsif (!$a{is_floor} && !$a{alive} && $a{move_block}) { |
790 | $root = $Crossfire::Data::TYPE{Wall}; |
804 | $root = $Deliantra::Data::TYPE{Wall}; |
791 | } elsif (!$a{is_floor} && $a{alive} && $a{tear_down}) { |
805 | } elsif (!$a{is_floor} && $a{alive} && $a{tear_down}) { |
792 | $root = $Crossfire::Data::TYPE{"Weak Wall"}; |
806 | $root = $Deliantra::Data::TYPE{"Weak Wall"}; |
793 | } else { |
807 | } else { |
794 | $root = $Crossfire::Data::TYPE{Misc}; |
808 | $root = $Deliantra::Data::TYPE{Misc}; |
795 | } |
809 | } |
796 | } |
810 | } |
797 | |
811 | |
798 | my @import = ($root); |
812 | my @import = ($root); |
799 | |
813 | |
800 | unshift @import, \%Crossfire::Data::DEFAULT_ATTR |
814 | unshift @import, \%Deliantra::Data::DEFAULT_ATTR |
801 | unless $type == 116; |
815 | unless $type == 116; |
802 | |
816 | |
803 | my (%ignore); |
817 | my (%ignore); |
804 | my (@section_order, %section, @attr_order); |
818 | my (@section_order, %section, @attr_order); |
805 | |
819 | |
806 | while (my $type = shift @import) { |
820 | while (my $type = shift @import) { |
|
|
821 | push @import, |
|
|
822 | grep $_, |
|
|
823 | map $Deliantra::Data::TYPE{$_}, |
807 | push @import, @{$type->{import} || []}; |
824 | @{$type->{import} || []}; |
808 | |
825 | |
809 | $attr->{$_} ||= $type->{$_} |
826 | $attr->{$_} ||= $type->{$_} |
810 | for qw(name desc use); |
827 | for qw(name desc use); |
811 | |
828 | |
812 | for (@{$type->{ignore} || []}) { |
829 | for (@{$type->{ignore} || []}) { |
… | |
… | |
901 | } |
918 | } |
902 | |
919 | |
903 | sub construct_tilecache_pb { |
920 | sub construct_tilecache_pb { |
904 | my ($idx, $cache) = @_; |
921 | my ($idx, $cache) = @_; |
905 | |
922 | |
906 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64; |
923 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, CACHESTRIDE * TILESIZE, TILESIZE * int +($idx + CACHESTRIDE - 1) / CACHESTRIDE; |
907 | |
924 | |
908 | while (my ($name, $tile) = each %$cache) { |
925 | while (my ($name, $tile) = each %$cache) { |
909 | my $tpb = delete $tile->{pb}; |
926 | my $tpb = delete $tile->{pb}; |
910 | my $ofs = $tile->{idx}; |
927 | my $ofs = $tile->{idx}; |
911 | |
928 | |
912 | for my $x (0 .. $tile->{w} - 1) { |
929 | for my $x (0 .. $tile->{w} - 1) { |
913 | for my $y (0 .. $tile->{h} - 1) { |
930 | for my $y (0 .. $tile->{h} - 1) { |
914 | my $idx = $ofs + $x + $y * $tile->{w}; |
931 | my $idx = $ofs + $x + $y * $tile->{w}; |
915 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
932 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
916 | $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); |
933 | $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE); |
917 | } |
934 | } |
918 | } |
935 | } |
919 | } |
936 | } |
920 | |
937 | |
921 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
938 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
… | |
… | |
937 | =cut |
954 | =cut |
938 | |
955 | |
939 | sub load_tilecache() { |
956 | sub load_tilecache() { |
940 | require Gtk2; |
957 | require Gtk2; |
941 | |
958 | |
942 | if (-e "$LIB/crossfire.0") { # Crossfire1 version |
|
|
943 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, |
|
|
944 | sub { |
|
|
945 | my $tile = read_pak "$LIB/crossfire.0"; |
|
|
946 | |
|
|
947 | my %cache; |
|
|
948 | |
|
|
949 | my $idx = 0; |
|
|
950 | |
|
|
951 | for my $name (sort keys %$tile) { |
|
|
952 | my $pb = new Gtk2::Gdk::PixbufLoader; |
|
|
953 | $pb->write ($tile->{$name}); |
|
|
954 | $pb->close; |
|
|
955 | my $pb = $pb->get_pixbuf; |
|
|
956 | |
|
|
957 | my $tile = $cache{$name} = { |
|
|
958 | pb => $pb, |
|
|
959 | idx => $idx, |
|
|
960 | w => int $pb->get_width / TILESIZE, |
|
|
961 | h => int $pb->get_height / TILESIZE, |
|
|
962 | }; |
|
|
963 | |
|
|
964 | $idx += $tile->{w} * $tile->{h}; |
|
|
965 | } |
|
|
966 | |
|
|
967 | construct_tilecache_pb $idx, \%cache; |
|
|
968 | |
|
|
969 | \%cache |
|
|
970 | }; |
|
|
971 | |
|
|
972 | } else { # Crossfire+ version |
|
|
973 | cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, |
959 | cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, |
974 | sub { |
960 | sub { |
975 | my %cache; |
961 | my %cache; |
976 | my $facedata = Storable::retrieve "$LIB/facedata"; |
962 | my $facedata = Storable::retrieve "$LIB/facedata"; |
977 | |
963 | |
978 | $facedata->{version} == 2 |
964 | $facedata->{version} == 2 |
979 | or die "$LIB/facedata: version mismatch, cannot proceed."; |
965 | or die "$LIB/facedata: version mismatch, cannot proceed."; |
980 | |
966 | |
981 | my $faces = $facedata->{faceinfo}; |
967 | my $faces = $facedata->{faceinfo}; |
982 | my $idx = 0; |
968 | my $idx = 0; |
983 | |
969 | |
984 | for (sort keys %$faces) { |
970 | for (sort keys %$faces) { |
985 | my ($face, $info) = ($_, $faces->{$_}); |
971 | my ($face, $info) = ($_, $faces->{$_}); |
986 | |
972 | |
987 | my $pb = new Gtk2::Gdk::PixbufLoader; |
973 | my $pb = new Gtk2::Gdk::PixbufLoader; |
988 | $pb->write ($info->{data32}); |
974 | $pb->write ($info->{data32}); |
989 | $pb->close; |
975 | $pb->close; |
990 | my $pb = $pb->get_pixbuf; |
976 | my $pb = $pb->get_pixbuf; |
991 | |
977 | |
992 | my $tile = $cache{$face} = { |
978 | my $tile = $cache{$face} = { |
993 | pb => $pb, |
979 | pb => $pb, |
994 | idx => $idx, |
980 | idx => $idx, |
995 | w => int $pb->get_width / TILESIZE, |
981 | w => int $pb->get_width / TILESIZE, |
996 | h => int $pb->get_height / TILESIZE, |
982 | h => int $pb->get_height / TILESIZE, |
997 | }; |
983 | }; |
998 | |
984 | |
999 | $idx += $tile->{w} * $tile->{h}; |
985 | $idx += $tile->{w} * $tile->{h}; |
1000 | } |
986 | } |
1001 | |
987 | |
1002 | construct_tilecache_pb $idx, \%cache; |
988 | construct_tilecache_pb $idx, \%cache; |
1003 | |
989 | |
1004 | \%cache |
990 | \%cache |
1005 | }; |
991 | }; |
1006 | } |
|
|
1007 | } |
992 | } |
|
|
993 | |
|
|
994 | =back |
1008 | |
995 | |
1009 | =head1 AUTHOR |
996 | =head1 AUTHOR |
1010 | |
997 | |
1011 | Marc Lehmann <schmorp@schmorp.de> |
998 | Marc Lehmann <schmorp@schmorp.de> |
1012 | http://home.schmorp.de/ |
999 | http://home.schmorp.de/ |
… | |
… | |
1015 | http://www.ta-sa.org/ |
1002 | http://www.ta-sa.org/ |
1016 | |
1003 | |
1017 | =cut |
1004 | =cut |
1018 | |
1005 | |
1019 | 1 |
1006 | 1 |
|
|
1007 | |