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.14 by root, Sat Feb 11 16:17:14 2006 UTC vs.
Revision 1.19 by root, Wed Feb 22 23:02:59 2006 UTC

12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use Storable; 16use Storable;
17use 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
20our @EXPORT = 21our @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
26our $LIB = $ENV{CROSSFIRE_LIBDIR} 24our $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
29sub TILESIZE (){ 32 } 27sub TILESIZE (){ 32 }
30 28
29our $CACHEDIR;
31our $ARCH; 30our %ARCH;
31our %FACE;
32our $TILE;
32 33
33our %FIELD_MULTILINE = ( 34our %FIELD_MULTILINE = (
34 msg => "endmsg", 35 msg => "endmsg",
35 lore => "endlore", 36 lore => "endlore",
36); 37);
46sub MOVE_ALL (){ 0xf } 47sub MOVE_ALL (){ 0xf }
47 48
48sub normalize_arch($) { 49sub 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
214sub 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
228sub 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
239sub 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
253sub editor_archs { 218sub 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>) 231arch_extents determines the extents of the given arch's face(s), linked
267# NOTE: non rectangular linked faces are not considered 232faces and single faces are handled here it returns (minx, miny, maxx,
233maxy)
234
235=cut
236
268sub arch_extends { 237sub 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
302sub init($) { 269sub 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 $type = arch_attr $arch
278
279Returns a hashref describing the object and its attributes. It can contain
280the 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 import
289
290=cut
291
292sub arch_attr($) {
293 my ($arch) = @_;
294
295 require Crossfire::Data;
296
297 my $attr;
298
299 if ($arch->{type} > 0) {
300 $attr = $Crossfire::Data::ATTR{$arch->{type}+0};
301 } else {
302 $attr = $Crossfire::Data::TYPE{Misc};
303
304 type:
305 for (@Crossfire::Data::ATTR0) {
306 my $req = $_->{required}
307 or die "internal error: ATTR0 without 'required'";
308
309 while (my ($k, $v) = each %$req) {
310 next type
311 unless $arch->{$k} == $v;
312 }
313
314 $attr = $_;
315 }
316 }
317
318 use PApp::Util;
319 warn PApp::Util::dumpval $attr;
320
321 $attr || \%Crossfire::Data::DEFAULT_ATTR;
322}
323
324sub arch_edit_sections {
325# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
326# edit_type = 0;
327# else if (edit_type != 0) {
328# // all flags from 'check_type' must be unset in this arch because they get recalculated now
329# edit_type &= ~check_type;
330# }
331#
332# }
333# if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 &&
334# getAttributeValue("alive", defarch) == 1 &&
335# (getAttributeValue("monster", defarch) == 1 ||
336# getAttributeValue("generator", defarch) == 1)) {
337# // Monster: monsters/npcs/generators
338# edit_type |= IGUIConstants.TILE_EDIT_MONSTER;
339# }
340# if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 &&
341# arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) {
342# // Walls
343# edit_type |= IGUIConstants.TILE_EDIT_WALL;
344# }
345# if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 &&
346# getAttributeValue("connected", defarch) != 0) {
347# // Connected Objects
348# edit_type |= IGUIConstants.TILE_EDIT_CONNECTED;
349# }
350# if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 &&
351# arch_type == 66 || arch_type == 41 || arch_type == 95) {
352# // Exit: teleporter/exit/trapdoors
353# edit_type |= IGUIConstants.TILE_EDIT_EXIT;
354# }
355# if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 &&
356# getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 ||
357# arch_type == 5 || arch_type == 36 || arch_type == 60 ||
358# arch_type == 85 || arch_type == 111 || arch_type == 123 ||
359# arch_type == 124 || arch_type == 130)) {
360# // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls
361# edit_type |= IGUIConstants.TILE_EDIT_TREASURE;
362# }
363# if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 &&
364# arch_type == 20 || arch_type == 23 || arch_type == 26 ||
365# arch_type == 91 || arch_type == 21 || arch_type == 24) {
366# // Door: door/special door/gates + keys
367# edit_type |= IGUIConstants.TILE_EDIT_DOOR;
368# }
369# if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 &&
370# getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 &&
371# arch_type <= 16) || arch_type == 33 || arch_type == 34 ||
372# arch_type == 35 || arch_type == 39 || arch_type == 70 ||
373# arch_type == 87 || arch_type == 99 || arch_type == 100 ||
374# arch_type == 104 || arch_type == 109 || arch_type == 113 ||
375# arch_type == 122 || arch_type == 3)) {
376# // Equipment: weapons/armour/wands/rods
377# edit_type |= IGUIConstants.TILE_EDIT_EQUIP;
378# }
379#
380# return(edit_type);
381#
382#
383}
384
385$CACHEDIR ||= "$ENV{HOME}/.crossfire";
386
387init $CACHEDIR;
307 388
308=head1 AUTHOR 389=head1 AUTHOR
309 390
310 Marc Lehmann <schmorp@schmorp.de> 391 Marc Lehmann <schmorp@schmorp.de>
311 http://home.schmorp.de/ 392 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines