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.6 by elmex, Sun Feb 5 00:28:09 2006 UTC vs.
Revision 1.12 by root, Thu Feb 9 19:59:29 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines