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.3 by elmex, Sun Mar 12 12:18:55 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 arch_is_monster);
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 arch_is_monster {
69 my ($a) = @_;
70 my $arch = $Crossfire::ARCH{$a->{_name}};
71 return $arch->{alive} and ($arch->{monster} or $arch->{generator});
72}
73
74sub stack_find {
75 my ($stack, $dir, $pred) = @_;
76
77
78 if ($dir eq 'from_top') {
79 my $i = scalar (@$stack) - 1;
80 if ($i < 0) { $i = 0 }
81
82 for (reverse @$stack) {
83 $pred->($_)
84 and return $i;
85
86 $i--;
87 }
88
89 } else {
90 my $i = 0;
91
92 for (@$stack) {
93 $pred->($_)
94 and return $i;
95
96 $i++;
97 }
98 }
99
100 return 0;
101
102}
103
104sub stack_find_floor {
105 my ($stack, $dir) = @_;
106 return stack_find ($stack, $dir, \&arch_is_floor);
107}
108
109sub stack_find_wall {
110 my ($stack, $dir) = @_;
111 return stack_find ($stack, $dir, \&arch_is_wall);
35} 112}
36 113
37sub insert_arch_stack_layer { 114sub insert_arch_stack_layer {
38 my ($stack, $arch) = @_; 115 my ($stack, $arch) = @_;
39 116

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines