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.15 by root, Sun Feb 12 04:50:24 2006 UTC vs.
Revision 1.26 by root, Thu Feb 23 05:23:01 2006 UTC

12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use Storable; 16use Storable;
17use File::Spec;
17use List::Util qw(min max); 18use List::Util qw(min max);
18 19
19#XXX: The map_* procedures scream for a map-object 20#XXX: The map_* procedures scream for a map-object
20 21
21our @EXPORT = 22our @EXPORT =
24our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
25 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; 26 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n";
26 27
27sub TILESIZE (){ 32 } 28sub TILESIZE (){ 32 }
28 29
29our $CACHEDIR; 30our $VARDIR;
30our %ARCH; 31our %ARCH;
31our %FACE; 32our %FACE;
32our $TILE; 33our $TILE;
33 34
34our %FIELD_MULTILINE = ( 35our %FIELD_MULTILINE = (
112sub read_pak($;$) { 113sub read_pak($;$) {
113 my ($path, $cache) = @_; 114 my ($path, $cache) = @_;
114 115
115 eval { 116 eval {
116 defined $cache 117 defined $cache
118 && -e $cache
117 && -M $cache < -M $path 119 && -M $cache < -M $path
118 && Storable::retrieve $cache 120 && Storable::retrieve ($cache)
119 } or do { 121 } or do {
120 my %pak; 122 my %pak;
121 123
122 open my $fh, "<:raw", $path 124 open my $fh, "<:raw", $path
123 or Carp::croak "$_[0]: $!"; 125 or Carp::croak "$_[0]: $!";
125 my ($type, $id, $len, $path) = split; 127 my ($type, $id, $len, $path) = split;
126 $path =~ s/.*\///; 128 $path =~ s/.*\///;
127 read $fh, $pak{$path}, $len; 129 read $fh, $pak{$path}, $len;
128 } 130 }
129 131
130 Storable::nstore \%pak, $cache 132 Storable::nstore (\%pak, $cache)
131 if defined $cache; 133 if defined $cache;
132 134
133 \%pak 135 \%pak
134 } 136 }
135} 137}
137sub read_arch($;$) { 139sub read_arch($;$) {
138 my ($path, $cache) = @_; 140 my ($path, $cache) = @_;
139 141
140 eval { 142 eval {
141 defined $cache 143 defined $cache
144 && -e $cache
142 && -M $cache < -M $path 145 && -M $cache < -M $path
143 && Storable::retrieve $cache 146 && Storable::retrieve ($cache)
144 } or do { 147 } or do {
145 my %arc; 148 my %arc;
146 my ($more, $prev); 149 my ($more, $prev);
147 150
148 open my $fh, "<:raw", $path 151 open my $fh, "<:raw", $path
203 } 206 }
204 } 207 }
205 208
206 undef $parse_block; # work around bug in perl not freeing $fh etc. 209 undef $parse_block; # work around bug in perl not freeing $fh etc.
207 210
211 warn "hoi\n";#d#
208 Storable::nstore \%arc, $cache 212 Storable::nstore (\%arc, $cache)
209 if defined $cache; 213 if defined $cache;
214 warn "hox\n";#d#
210 215
211 \%arc 216 \%arc
212 } 217 }
213} 218}
214 219
224 } 229 }
225 230
226 \%paths 231 \%paths
227} 232}
228 233
234=item ($minx, $miny, $maxx, $maxy) = arch_extents $arch
235
229# arch_extents determines the extents of a given arch 236arch_extents determines the extents of the given arch's face(s), linked
230# bigfaces, linked faces and single faces are handled here 237faces and single faces are handled here it returns (minx, miny, maxx,
231# it returns (minx, miny, maxx, maxy) 238maxy)
239
240=cut
241
232sub arch_extents { 242sub arch_extents {
233 my ($a) = @_; 243 my ($a) = @_;
234 244
235 my $o = $ARCH{$a->{_name}} 245 my $o = $ARCH{$a->{_name}}
236 or return; 246 or return;
259 # single face 269 # single face
260 return (0, 0, 0, 0); 270 return (0, 0, 0, 0);
261 } 271 }
262} 272}
263 273
274=item $type = arch_attr $arch
275
276Returns a hashref describing the object and its attributes. It can contain
277the following keys:
278
279 name the name, suitable for display purposes
280 ignore
281 attr
282 desc
283 use
284 section => [name => \%attr, name => \%attr]
285 import
286
287=cut
288
289sub arch_attr($) {
290 my ($arch) = @_;
291
292 require Crossfire::Data;
293
294 my $attr;
295
296 if ($arch->{type} > 0) {
297 $attr = $Crossfire::Data::ATTR{$arch->{type}+0};
298 } else {
299 $attr = $Crossfire::Data::TYPE{Misc};
300
301 type:
302 for (@Crossfire::Data::ATTR0) {
303 my $req = $_->{required}
304 or die "internal error: ATTR0 without 'required'";
305
306 while (my ($k, $v) = each %$req) {
307 next type
308 unless $arch->{$k} == $v;
309 }
310
311 $attr = $_;
312 }
313 }
314
315 $attr || \%Crossfire::Data::DEFAULT_ATTR;
316}
317
318sub arch_edit_sections {
319# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
320# edit_type = 0;
321# else if (edit_type != 0) {
322# // all flags from 'check_type' must be unset in this arch because they get recalculated now
323# edit_type &= ~check_type;
324# }
325#
326# }
327# if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 &&
328# getAttributeValue("alive", defarch) == 1 &&
329# (getAttributeValue("monster", defarch) == 1 ||
330# getAttributeValue("generator", defarch) == 1)) {
331# // Monster: monsters/npcs/generators
332# edit_type |= IGUIConstants.TILE_EDIT_MONSTER;
333# }
334# if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 &&
335# arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) {
336# // Walls
337# edit_type |= IGUIConstants.TILE_EDIT_WALL;
338# }
339# if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 &&
340# getAttributeValue("connected", defarch) != 0) {
341# // Connected Objects
342# edit_type |= IGUIConstants.TILE_EDIT_CONNECTED;
343# }
344# if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 &&
345# arch_type == 66 || arch_type == 41 || arch_type == 95) {
346# // Exit: teleporter/exit/trapdoors
347# edit_type |= IGUIConstants.TILE_EDIT_EXIT;
348# }
349# if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 &&
350# getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 ||
351# arch_type == 5 || arch_type == 36 || arch_type == 60 ||
352# arch_type == 85 || arch_type == 111 || arch_type == 123 ||
353# arch_type == 124 || arch_type == 130)) {
354# // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls
355# edit_type |= IGUIConstants.TILE_EDIT_TREASURE;
356# }
357# if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 &&
358# arch_type == 20 || arch_type == 23 || arch_type == 26 ||
359# arch_type == 91 || arch_type == 21 || arch_type == 24) {
360# // Door: door/special door/gates + keys
361# edit_type |= IGUIConstants.TILE_EDIT_DOOR;
362# }
363# if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 &&
364# getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 &&
365# arch_type <= 16) || arch_type == 33 || arch_type == 34 ||
366# arch_type == 35 || arch_type == 39 || arch_type == 70 ||
367# arch_type == 87 || arch_type == 99 || arch_type == 100 ||
368# arch_type == 104 || arch_type == 109 || arch_type == 113 ||
369# arch_type == 122 || arch_type == 3)) {
370# // Equipment: weapons/armour/wands/rods
371# edit_type |= IGUIConstants.TILE_EDIT_EQUIP;
372# }
373#
374# return(edit_type);
375#
376#
377}
378
264sub init($) { 379sub init($) {
265 my ($cachedir) = @_; 380 my ($cachedir) = @_;
266 381
267 return if %ARCH; 382 return if %ARCH;
268 383
384 mkdir $cachedir, 0777;
269 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 385 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
270} 386}
271 387
272$CACHEDIR ||= "$ENV{HOME}/.crossfire"; 388$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir;
273 389
274init $CACHEDIR; 390init $VARDIR;
275 391
276=head1 AUTHOR 392=head1 AUTHOR
277 393
278 Marc Lehmann <schmorp@schmorp.de> 394 Marc Lehmann <schmorp@schmorp.de>
279 http://home.schmorp.de/ 395 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines