… | |
… | |
13 | |
13 | |
14 | use Carp (); |
14 | use Carp (); |
15 | use Storable; |
15 | use Storable; |
16 | use List::Util qw(min max); |
16 | use List::Util qw(min max); |
17 | |
17 | |
18 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer); |
18 | use Crossfire; |
|
|
19 | use Crossfire::MapWidget; |
|
|
20 | |
|
|
21 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall); |
|
|
22 | |
|
|
23 | sub new_arch_pb { |
|
|
24 | # this is awful, is this really the best way? |
|
|
25 | my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
|
|
26 | return $pb; |
|
|
27 | } |
|
|
28 | |
|
|
29 | sub fill_pb_from_arch { |
|
|
30 | my ($pb, $arch) = @_; |
|
|
31 | |
|
|
32 | $pb->fill (0x00000000); |
|
|
33 | $TILE->composite ($pb, |
|
|
34 | 0, 0, |
|
|
35 | TILESIZE, TILESIZE, |
|
|
36 | - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64, |
|
|
37 | 1, 1, 'nearest', 255 |
|
|
38 | ); |
|
|
39 | } |
19 | |
40 | |
20 | sub classify_arch_layer { |
41 | sub classify_arch_layer { |
21 | my ($arch) = @_; |
42 | my ($arch) = @_; |
22 | |
43 | |
23 | if ($arch->{invisible}) { # just a heuristic for 'special' tiles (er. pedestals) |
44 | if ($arch->{invisible}) { # just a heuristic for 'special' tiles (er. pedestals) |
… | |
… | |
30 | |
51 | |
31 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
52 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
32 | |
53 | |
33 | return 'between'; |
54 | return 'between'; |
34 | } |
55 | } |
|
|
56 | } |
|
|
57 | |
|
|
58 | sub arch_is_floor { |
|
|
59 | my ($a) = @_; |
|
|
60 | return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
|
|
61 | } |
|
|
62 | |
|
|
63 | sub arch_is_wall { |
|
|
64 | my ($a) = @_; |
|
|
65 | return $Crossfire::ARCH{$a->{_name}}->{no_pass}; |
|
|
66 | } |
|
|
67 | |
|
|
68 | sub stack_find { |
|
|
69 | my ($stack, $dir, $pred) = @_; |
|
|
70 | |
|
|
71 | |
|
|
72 | if ($dir eq 'from_top') { |
|
|
73 | my $i = scalar (@$stack) - 1; |
|
|
74 | if ($i < 0) { $i = 0 } |
|
|
75 | |
|
|
76 | for (reverse @$stack) { |
|
|
77 | $pred->($_) |
|
|
78 | and return $i; |
|
|
79 | |
|
|
80 | $i--; |
|
|
81 | } |
|
|
82 | |
|
|
83 | } else { |
|
|
84 | my $i = 0; |
|
|
85 | |
|
|
86 | for (@$stack) { |
|
|
87 | $pred->($_) |
|
|
88 | and return $i; |
|
|
89 | |
|
|
90 | $i++; |
|
|
91 | } |
|
|
92 | } |
|
|
93 | |
|
|
94 | return 0; |
|
|
95 | |
|
|
96 | } |
|
|
97 | |
|
|
98 | sub stack_find_floor { |
|
|
99 | my ($stack, $dir) = @_; |
|
|
100 | return stack_find ($stack, $dir, \&arch_is_floor); |
|
|
101 | } |
|
|
102 | |
|
|
103 | sub stack_find_wall { |
|
|
104 | my ($stack, $dir) = @_; |
|
|
105 | return stack_find ($stack, $dir, \&arch_is_wall); |
35 | } |
106 | } |
36 | |
107 | |
37 | sub insert_arch_stack_layer { |
108 | sub insert_arch_stack_layer { |
38 | my ($stack, $arch) = @_; |
109 | my ($stack, $arch) = @_; |
39 | |
110 | |