… | |
… | |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
16 | use Storable; |
|
|
17 | use List::Util qw(min max); |
17 | |
18 | |
18 | #XXX: The map_* procedures scream for a map-object |
19 | #XXX: The map_* procedures scream for a map-object |
19 | |
20 | |
20 | our @EXPORT = |
21 | our @EXPORT = |
21 | qw(read_pak read_arch $ARCH TILESIZE editor_archs |
22 | qw(read_pak read_arch %ARCH TILESIZE $TILE %FACE editor_archs arch_extents); |
22 | arch_extends |
|
|
23 | map_get_tile_stack map_push_tile_stack map_pop_tile_stack |
|
|
24 | ); |
|
|
25 | |
23 | |
26 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
24 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
27 | or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; |
25 | or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; |
28 | |
26 | |
29 | sub TILESIZE (){ 32 } |
27 | sub TILESIZE (){ 32 } |
30 | |
28 | |
|
|
29 | our $CACHEDIR; |
31 | our $ARCH; |
30 | our %ARCH; |
|
|
31 | our %FACE; |
|
|
32 | our $TILE; |
32 | |
33 | |
33 | our %FIELD_MULTILINE = ( |
34 | our %FIELD_MULTILINE = ( |
34 | msg => "endmsg", |
35 | msg => "endmsg", |
35 | lore => "endlore", |
36 | lore => "endlore", |
36 | ); |
37 | ); |
… | |
… | |
46 | sub MOVE_ALL (){ 0xf } |
47 | sub MOVE_ALL (){ 0xf } |
47 | |
48 | |
48 | sub normalize_arch($) { |
49 | sub normalize_arch($) { |
49 | my ($ob) = @_; |
50 | my ($ob) = @_; |
50 | |
51 | |
51 | my $arch = $ARCH->{$ob->{_name}} |
52 | my $arch = $ARCH{$ob->{_name}} |
52 | or (warn "$ob->{_name}: no such archetype", return $ob); |
53 | or (warn "$ob->{_name}: no such archetype", return $ob); |
53 | |
54 | |
54 | delete $ob->{$_} for qw(can_knockback can_parry can_impale can_cut can_dam_armour can_apply); |
55 | delete $ob->{$_} for qw(can_knockback can_parry can_impale can_cut can_dam_armour can_apply); |
55 | |
56 | |
56 | if ($arch->{type} == 22) { # map |
57 | if ($arch->{type} == 22) { # map |
… | |
… | |
98 | } |
99 | } |
99 | |
100 | |
100 | # if value matches archetype default, delete |
101 | # if value matches archetype default, delete |
101 | while (my ($k, $v) = each %$ob) { |
102 | while (my ($k, $v) = each %$ob) { |
102 | if (exists $arch->{$k} and $arch->{$k} eq $v) { |
103 | if (exists $arch->{$k} and $arch->{$k} eq $v) { |
|
|
104 | next if $k eq "_name"; |
103 | delete $ob->{$k}; |
105 | delete $ob->{$k}; |
104 | } |
106 | } |
105 | } |
107 | } |
106 | |
108 | |
107 | $ob |
109 | $ob |
… | |
… | |
208 | |
210 | |
209 | \%arc |
211 | \%arc |
210 | } |
212 | } |
211 | } |
213 | } |
212 | |
214 | |
213 | # returns the arch/object stack from a tile on a map |
|
|
214 | sub map_get_tile_stack { |
|
|
215 | my ($map, $x, $y) = @_; |
|
|
216 | my $as; |
|
|
217 | |
|
|
218 | if ($x > 0 || $x < $map->{width} |
|
|
219 | || $y > 0 || $y < $map->{height}) { |
|
|
220 | |
|
|
221 | $as = $map->{map}{map}[$x][$y] || []; |
|
|
222 | } |
|
|
223 | |
|
|
224 | return $as; |
|
|
225 | } |
|
|
226 | |
|
|
227 | # pop the topmost arch/object from the stack of a tile on a map |
|
|
228 | sub map_pop_tile_stack { |
|
|
229 | my ($map, $x, $y) = @_; |
|
|
230 | |
|
|
231 | if ($x > 0 || $x < $map->{width} |
|
|
232 | || $y > 0 || $y < $map->{height}) { |
|
|
233 | |
|
|
234 | pop @{$map->{map}{map}[$x][$y]}; |
|
|
235 | } |
|
|
236 | } |
|
|
237 | |
|
|
238 | # pushes the arch/object on the stack of a tile on a map |
|
|
239 | sub map_push_tile_stack { |
|
|
240 | my ($map, $x, $y, $arch) = @_; |
|
|
241 | |
|
|
242 | if ($x > 0 || $x < $map->{width} |
|
|
243 | || $y > 0 || $y < $map->{height}) { |
|
|
244 | |
|
|
245 | push @{$map->{map}{map}[$x][$y]}, $arch; |
|
|
246 | } |
|
|
247 | } |
|
|
248 | |
|
|
249 | |
|
|
250 | # put all archs into a hash with editor_face as it's key |
215 | # put all archs into a hash with editor_face as it's key |
251 | # NOTE: the arrays in the hash values are references to |
216 | # NOTE: the arrays in the hash values are references to |
252 | # the archs from $ARCH |
217 | # the archs from $ARCH |
253 | sub editor_archs { |
218 | sub editor_archs { |
254 | my %paths; |
219 | my %paths; |
255 | |
220 | |
256 | for (keys %$ARCH) { |
221 | for (keys %ARCH) { |
257 | my $arch = $ARCH->{$_}; |
222 | my $arch = $ARCH{$_}; |
258 | push @{$paths{$arch->{editor_folder}}}, \$arch; |
223 | push @{$paths{$arch->{editor_folder}}}, \$arch; |
259 | } |
224 | } |
260 | |
225 | |
261 | return \%paths; |
226 | \%paths |
262 | } |
227 | } |
263 | |
228 | |
264 | # arch_extends determines how the arch looks like on the map, |
229 | =item ($minx, $miny, $maxx, $maxy) = arch_extents $arch |
265 | # bigfaces, linked faces and single faces are handled here |
230 | |
266 | # it returns (<xoffset>, <yoffset>, <width>, <height>) |
231 | arch_extents determines the extents of the given arch's face(s), linked |
267 | # NOTE: non rectangular linked faces are not considered |
232 | faces and single faces are handled here it returns (minx, miny, maxx, |
|
|
233 | maxy) |
|
|
234 | |
|
|
235 | =cut |
|
|
236 | |
268 | sub arch_extends { |
237 | sub arch_extents { |
269 | my ($a) = @_; |
238 | my ($a) = @_; |
270 | |
239 | |
271 | my $TC = \%Crossfire::Tilecache::TILECACHE; |
240 | my $o = $ARCH{$a->{_name}} |
272 | |
|
|
273 | my $facename = |
|
|
274 | $a->{face} || $ARCH->{$a->{_name}}->{face} |
|
|
275 | or return (); |
241 | or return; |
276 | |
242 | |
277 | my $tile = $TC->{$facename} |
243 | my $face = $FACE{$a->{face} || $o->{face}} |
278 | or (warn "no gfx found for arch '$facename' in arch_size ()"), return; |
244 | or (warn "no face data found for arch '$a->{_name}'"), return; |
279 | |
245 | |
280 | if ($tile->{w} > 1 || $tile->{h} > 1) { |
246 | if ($face->{w} > 1 || $face->{h} > 1) { |
281 | # bigfaces |
247 | # bigface |
282 | return (0, 0, $tile->{w}, $tile->{h}); |
248 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
283 | |
249 | |
284 | } elsif ($a->{more}) { |
250 | } elsif ($o->{more}) { |
285 | # linked faces |
251 | # linked face |
286 | my ($miw, $mih, $maw, $mah) = (0, 0, 0, 0); |
252 | my ($minx, $miny, $maxx, $maxy) = ($o->{x}, $o->{y}) x 2; |
287 | do { |
|
|
288 | $miw > (0 + $a->{x}) and $miw = $a->{x}; |
|
|
289 | $mih > (0 + $a->{y}) and $mih = $a->{y}; |
|
|
290 | $maw < (0 + $a->{x}) and $maw = $a->{x}; |
|
|
291 | $mah < (0 + $a->{y}) and $mah = $a->{y}; |
|
|
292 | } while $a = $a->{more}; |
|
|
293 | |
253 | |
294 | return ($miw, $mih, ($maw - $miw) + 1, ($mah - $mih) + 1) |
254 | for (; $o; $o = $o->{more}) { |
|
|
255 | $minx = min $minx, $o->{x}; |
|
|
256 | $miny = min $miny, $o->{y}; |
|
|
257 | $maxx = max $maxx, $o->{x}; |
|
|
258 | $maxy = max $maxy, $o->{y}; |
|
|
259 | } |
|
|
260 | |
|
|
261 | return ($minx, $miny, $maxx, $maxy); |
295 | |
262 | |
296 | } else { |
263 | } else { |
297 | # single face |
264 | # single face |
298 | return (0, 0, 1, 1); |
265 | return (0, 0, 0, 0); |
299 | } |
266 | } |
300 | } |
267 | } |
301 | |
268 | |
302 | sub init($) { |
269 | sub init($) { |
303 | my ($cachedir) = @_; |
270 | my ($cachedir) = @_; |
304 | |
271 | |
|
|
272 | return if %ARCH; |
|
|
273 | |
305 | $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
274 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
306 | } |
275 | } |
|
|
276 | |
|
|
277 | =item $data = arch_attr $arch |
|
|
278 | |
|
|
279 | Returns a hashref describing the object and its attributes. It can contain |
|
|
280 | the following keys: |
|
|
281 | |
|
|
282 | name the name, suitable for display purposes |
|
|
283 | ignore |
|
|
284 | attr |
|
|
285 | desc |
|
|
286 | use |
|
|
287 | section => [name => \%attr, name => \%attr] |
|
|
288 | |
|
|
289 | =cut |
|
|
290 | |
|
|
291 | sub arch_attr($) { |
|
|
292 | my ($arch) = @_; |
|
|
293 | |
|
|
294 | require Crossfire::Data; |
|
|
295 | |
|
|
296 | my $attr; |
|
|
297 | |
|
|
298 | if ($arch->{type} > 0) { |
|
|
299 | $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; |
|
|
300 | } else { |
|
|
301 | $attr = $Crossfire::Data::TYPE{Misc}; |
|
|
302 | |
|
|
303 | type: |
|
|
304 | for (@Crossfire::Data::ATTR0) { |
|
|
305 | my $req = $_->{required} |
|
|
306 | or die "internal error: ATTR0 without 'required'"; |
|
|
307 | |
|
|
308 | while (my ($k, $v) = each %$req) { |
|
|
309 | next type |
|
|
310 | unless $arch->{$k} == $v; |
|
|
311 | } |
|
|
312 | |
|
|
313 | $attr = $_; |
|
|
314 | } |
|
|
315 | } |
|
|
316 | |
|
|
317 | use PApp::Util; |
|
|
318 | warn PApp::Util::dumpval $attr; |
|
|
319 | } |
|
|
320 | |
|
|
321 | sub arch_edit_sections { |
|
|
322 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
|
|
323 | # edit_type = 0; |
|
|
324 | # else if (edit_type != 0) { |
|
|
325 | # // all flags from 'check_type' must be unset in this arch because they get recalculated now |
|
|
326 | # edit_type &= ~check_type; |
|
|
327 | # } |
|
|
328 | # |
|
|
329 | # } |
|
|
330 | # if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 && |
|
|
331 | # getAttributeValue("alive", defarch) == 1 && |
|
|
332 | # (getAttributeValue("monster", defarch) == 1 || |
|
|
333 | # getAttributeValue("generator", defarch) == 1)) { |
|
|
334 | # // Monster: monsters/npcs/generators |
|
|
335 | # edit_type |= IGUIConstants.TILE_EDIT_MONSTER; |
|
|
336 | # } |
|
|
337 | # if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 && |
|
|
338 | # arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) { |
|
|
339 | # // Walls |
|
|
340 | # edit_type |= IGUIConstants.TILE_EDIT_WALL; |
|
|
341 | # } |
|
|
342 | # if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 && |
|
|
343 | # getAttributeValue("connected", defarch) != 0) { |
|
|
344 | # // Connected Objects |
|
|
345 | # edit_type |= IGUIConstants.TILE_EDIT_CONNECTED; |
|
|
346 | # } |
|
|
347 | # if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 && |
|
|
348 | # arch_type == 66 || arch_type == 41 || arch_type == 95) { |
|
|
349 | # // Exit: teleporter/exit/trapdoors |
|
|
350 | # edit_type |= IGUIConstants.TILE_EDIT_EXIT; |
|
|
351 | # } |
|
|
352 | # if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 && |
|
|
353 | # getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 || |
|
|
354 | # arch_type == 5 || arch_type == 36 || arch_type == 60 || |
|
|
355 | # arch_type == 85 || arch_type == 111 || arch_type == 123 || |
|
|
356 | # arch_type == 124 || arch_type == 130)) { |
|
|
357 | # // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls |
|
|
358 | # edit_type |= IGUIConstants.TILE_EDIT_TREASURE; |
|
|
359 | # } |
|
|
360 | # if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 && |
|
|
361 | # arch_type == 20 || arch_type == 23 || arch_type == 26 || |
|
|
362 | # arch_type == 91 || arch_type == 21 || arch_type == 24) { |
|
|
363 | # // Door: door/special door/gates + keys |
|
|
364 | # edit_type |= IGUIConstants.TILE_EDIT_DOOR; |
|
|
365 | # } |
|
|
366 | # if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 && |
|
|
367 | # getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 && |
|
|
368 | # arch_type <= 16) || arch_type == 33 || arch_type == 34 || |
|
|
369 | # arch_type == 35 || arch_type == 39 || arch_type == 70 || |
|
|
370 | # arch_type == 87 || arch_type == 99 || arch_type == 100 || |
|
|
371 | # arch_type == 104 || arch_type == 109 || arch_type == 113 || |
|
|
372 | # arch_type == 122 || arch_type == 3)) { |
|
|
373 | # // Equipment: weapons/armour/wands/rods |
|
|
374 | # edit_type |= IGUIConstants.TILE_EDIT_EQUIP; |
|
|
375 | # } |
|
|
376 | # |
|
|
377 | # return(edit_type); |
|
|
378 | # |
|
|
379 | # |
|
|
380 | } |
|
|
381 | |
|
|
382 | $CACHEDIR ||= "$ENV{HOME}/.crossfire"; |
|
|
383 | |
|
|
384 | init $CACHEDIR; |
307 | |
385 | |
308 | =head1 AUTHOR |
386 | =head1 AUTHOR |
309 | |
387 | |
310 | Marc Lehmann <schmorp@schmorp.de> |
388 | Marc Lehmann <schmorp@schmorp.de> |
311 | http://home.schmorp.de/ |
389 | http://home.schmorp.de/ |