ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/Util.pm
(Generate patch)

Comparing deliantra/gde/GCE/Util.pm (file contents):
Revision 1.1 by elmex, Mon Feb 20 18:21:04 2006 UTC vs.
Revision 1.2 by elmex, Fri Mar 10 20:32:47 2006 UTC

13 13
14use Carp (); 14use Carp ();
15use Storable; 15use Storable;
16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer); 18use Crossfire;
19use Crossfire::MapWidget;
20
21our @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
23sub 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
29sub 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
20sub classify_arch_layer { 41sub 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
58sub arch_is_floor {
59 my ($a) = @_;
60 return $Crossfire::ARCH{$a->{_name}}->{is_floor};
61}
62
63sub arch_is_wall {
64 my ($a) = @_;
65 return $Crossfire::ARCH{$a->{_name}}->{no_pass};
66}
67
68sub 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
98sub stack_find_floor {
99 my ($stack, $dir) = @_;
100 return stack_find ($stack, $dir, \&arch_is_floor);
101}
102
103sub stack_find_wall {
104 my ($stack, $dir) = @_;
105 return stack_find ($stack, $dir, \&arch_is_wall);
35} 106}
36 107
37sub insert_arch_stack_layer { 108sub insert_arch_stack_layer {
38 my ($stack, $arch) = @_; 109 my ($stack, $arch) = @_;
39 110

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines