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.5 by root, Sun Feb 5 00:25:33 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;
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 );
14 24
15our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
16 or die "\$CROSSFIRE_LIBDIR must be set\n"; 26 or die "\$CROSSFIRE_LIBDIR must be set\n";
17 27
18sub T (){ 32 } 28sub TILESIZE (){ 32 }
19 29
20our $ARCH; 30our $ARCH;
21our $TILE;
22 31
23sub read_pak($;$) { 32sub read_pak($;$) {
24 my ($path, $cache) = @_; 33 my ($path, $cache) = @_;
25 34
26 eval { 35 eval {
121 130
122 \%arc 131 \%arc
123 } 132 }
124} 133}
125 134
126sub 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 {
127 my ($mapa) = @_; 191 my ($a) = @_;
128 192
129 my %meta; 193 my $TC = \%Crossfire::Tilecache::TILECACHE;
130 194
131 my ($mapx, $mapy); 195 my $facename =
196 $a->{face} || $ARCH->{$a->{_name}}->{face}
197 or return ();
132 198
133 my $map; 199 my $tile = $TC->{$facename}
200 or (warn "no gfx found for arch '$facename' in arch_size ()"), return;
134 201
135 for (@{ $mapa->{arch} }) { 202 if ($tile->{w} > 1 || $tile->{h} > 1) {
136 my ($x, $y) = ($_->{x}, $_->{y}); 203 # bigfaces
204 return (0, 0, $tile->{w}, $tile->{h});
137 205
138 if ($_->{_name} eq "map") { 206 } elsif ($a->{more}) {
139 $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};
140 215
141 $mapx = $_->{width} || $x; 216 return ($miw, $mih, ($maw - $miw) + 1, ($mah - $mih) + 1)
142 $mapy = $_->{height} || $y; 217
143 } else { 218 } else {
144 push @{ $map->[$x][$y] }, $_; 219 # single face
145 220 return (0, 0, 1, 1);
146 # arch map is unreliable w.r.t. width and height
147 $mapx = $x + 1 if $mapx <= $x;
148 $mapy = $y + 1 if $mapy <= $y;
149 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
150 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
151 }
152 } 221 }
153
154 $meta{width} = $mapx;
155 $meta{height} = $mapy;
156
157 \%meta
158} 222}
159 223
160sub init($) { 224sub init($) {
161 my ($cachedir) = @_; 225 my ($cachedir) = @_;
162 226
163 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 227 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
164 $TILE = read_pak "$LIB/crossfire.0", "$cachedir/crossfire.0.pst";
165} 228}
166 229
167=head1 AUTHOR 230=head1 AUTHOR
168 231
169 Marc Lehmann <schmorp@schmorp.de> 232 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines