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

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.4 by root, Sun Feb 5 00:18:26 2006 UTC vs.
Revision 1.12 by root, Thu Feb 9 19:59:29 2006 UTC

8 8
9our $VERSION = '0.1'; 9our $VERSION = '0.1';
10 10
11use strict; 11use strict;
12 12
13use base 'Exporter';
14
13use Storable; 15use Storable;
14use List::Util qw(max); 16
17#XXX: The map_* procedures scream for a map-object
18
19our @EXPORT =
20 qw(read_pak read_arch $ARCH TILESIZE editor_archs
21 arch_extends
22 map_get_tile_stack map_push_tile_stack map_pop_tile_stack
23 );
15 24
16our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
17 or die "\$CROSSFIRE_LIBDIR must be set\n"; 26 or die "\$CROSSFIRE_LIBDIR must be set\n";
18 27
19sub T (){ 32 } 28sub TILESIZE (){ 32 }
20 29
21our $ARCH; 30our $ARCH;
22our $TILE;
23 31
24sub read_pak($;$) { 32sub read_pak($;$) {
25 my ($path, $cache) = @_; 33 my ($path, $cache) = @_;
26 34
27 eval { 35 eval {
122 130
123 \%arc 131 \%arc
124 } 132 }
125} 133}
126 134
127sub arch2map($;$) { 135# returns the arch/object stack from a tile on a map
136sub map_get_tile_stack {
137 my ($map, $x, $y) = @_;
138 my $as;
139
140 if ($x > 0 || $x < $map->{width}
141 || $y > 0 || $y < $map->{height}) {
142
143 $as = $map->{map}{map}[$x][$y] || [];
144 }
145
146 return $as;
147}
148
149# pop the topmost arch/object from the stack of a tile on a map
150sub map_pop_tile_stack {
151 my ($map, $x, $y) = @_;
152
153 if ($x > 0 || $x < $map->{width}
154 || $y > 0 || $y < $map->{height}) {
155
156 pop @{$map->{map}{map}[$x][$y]};
157 }
158}
159
160# pushes the arch/object on the stack of a tile on a map
161sub map_push_tile_stack {
162 my ($map, $x, $y, $arch) = @_;
163
164 if ($x > 0 || $x < $map->{width}
165 || $y > 0 || $y < $map->{height}) {
166
167 push @{$map->{map}{map}[$x][$y]}, $arch;
168 }
169}
170
171
172# put all archs into a hash with editor_face as it's key
173# NOTE: the arrays in the hash values are references to
174# the archs from $ARCH
175sub editor_archs {
176 my %paths;
177
178 for (keys %$ARCH) {
179 my $arch = $ARCH->{$_};
180 push @{$paths{$arch->{editor_folder}}}, \$arch;
181 }
182
183 return \%paths;
184}
185
186# arch_extends determines how the arch looks like on the map,
187# bigfaces, linked faces and single faces are handled here
188# it returns (<xoffset>, <yoffset>, <width>, <height>)
189# NOTE: non rectangular linked faces are not considered
190sub arch_extends {
128 my ($mapa) = @_; 191 my ($a) = @_;
129 192
130 my %meta; 193 my $TC = \%Crossfire::Tilecache::TILECACHE;
131 194
132 my ($mapx, $mapy); 195 my $facename =
196 $a->{face} || $ARCH->{$a->{_name}}->{face}
197 or return ();
133 198
134 my $map; 199 my $tile = $TC->{$facename}
200 or (warn "no gfx found for arch '$facename' in arch_size ()"), return;
135 201
136 for (@{ $mapa->{arch} }) { 202 if ($tile->{w} > 1 || $tile->{h} > 1) {
137 my ($x, $y) = ($_->{x}, $_->{y}); 203 # bigfaces
204 return (0, 0, $tile->{w}, $tile->{h});
138 205
139 if ($_->{_name} eq "map") { 206 } elsif ($a->{more}) {
140 $meta{info} = $_; 207 # linked faces
208 my ($miw, $mih, $maw, $mah) = (0, 0, 0, 0);
209 do {
210 $miw > (0 + $a->{x}) and $miw = $a->{x};
211 $mih > (0 + $a->{y}) and $mih = $a->{y};
212 $maw < (0 + $a->{x}) and $maw = $a->{x};
213 $mah < (0 + $a->{y}) and $mah = $a->{y};
214 } while $a = $a->{more};
141 215
142 $mapx = $_->{width} || $x; 216 return ($miw, $mih, ($maw - $miw) + 1, ($mah - $mih) + 1)
143 $mapy = $_->{height} || $y; 217
144 } else { 218 } else {
145 push @{ $map->[$x][$y] }, $_; 219 # single face
146 220 return (0, 0, 1, 1);
147 # arch map is unreliable w.r.t. width and height
148 $mapx = $x + 1 if $mapx <= $x;
149 $mapy = $y + 1 if $mapy <= $y;
150 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
151 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
152 }
153 } 221 }
154
155 $meta{width} = $mapx;
156 $meta{height} = $mapy;
157
158 \%meta
159} 222}
160 223
161sub init($) { 224sub init($) {
162 my ($cachedir) = @_; 225 my ($cachedir) = @_;
163 226
164 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 227 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
165 $TILE = read_pak "$LIB/crossfire.0", "$cachedir/crossfire.0.pst";
166} 228}
167 229
168=head1 AUTHOR 230=head1 AUTHOR
169 231
170 Marc Lehmann <schmorp@schmorp.de> 232 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines