… | |
… | |
37 | msg => "endmsg", |
37 | msg => "endmsg", |
38 | lore => "endlore", |
38 | lore => "endlore", |
39 | maplore => "endmaplore", |
39 | maplore => "endmaplore", |
40 | ); |
40 | ); |
41 | |
41 | |
|
|
42 | # movement bit type, PITA |
|
|
43 | our %FIELD_MOVEMENT = map +($_ => undef), |
|
|
44 | qw(move_type move_block move_allow move_on move_off move_slow); |
|
|
45 | |
42 | # same as in server save routine, to (hopefully) be compatible |
46 | # same as in server save routine, to (hopefully) be compatible |
43 | # to the other editors. |
47 | # to the other editors. |
|
|
48 | our @FIELD_ORDER_MAP = (qw( |
|
|
49 | name swap_time reset_timeout fixed_resettime difficulty region |
|
|
50 | shopitems shopgreed shopmin shopmax shoprace |
|
|
51 | darkness width height enter_x enter_y msg maplore |
|
|
52 | unique template |
|
|
53 | outdoor temp pressure humid windspeed winddir sky nosmooth |
|
|
54 | tile_path_1 tile_path_2 tile_path_3 tile_path_4 |
|
|
55 | )); |
|
|
56 | |
44 | our @FIELD_ORDER = (qw( |
57 | our @FIELD_ORDER = (qw( |
|
|
58 | elevation |
|
|
59 | |
45 | name name_pl custom_name title race |
60 | name name_pl custom_name title race |
46 | slaying skill msg lore other_arch face |
61 | slaying skill msg lore other_arch face |
47 | #events |
62 | #todo-events |
48 | animation is_animated |
63 | animation is_animated |
49 | Str Dex Con Wis Pow Cha Int |
64 | str dex con wis pow cha int |
50 | hp maxhp sp maxsp grace maxgrace |
65 | hp maxhp sp maxsp grace maxgrace |
51 | exp perm_exp expmul |
66 | exp perm_exp expmul |
52 | food dam luck wc ac x y speed speed_left move_state attack_movement |
67 | food dam luck wc ac x y speed speed_left move_state attack_movement |
53 | nrof level direction type subtype |
68 | nrof level direction type subtype attacktype |
54 | |
69 | |
55 | resist_physical resist_magic resist_fire resist_electricity |
70 | resist_physical resist_magic resist_fire resist_electricity |
56 | resist_cold resist_confusion resist_acid resist_drain |
71 | resist_cold resist_confusion resist_acid resist_drain |
57 | resist_weaponmagic resist_ghosthit resist_poison resist_slow |
72 | resist_weaponmagic resist_ghosthit resist_poison resist_slow |
58 | resist_paralyze resist_turn_undead resist_fear resist_cancellation |
73 | resist_paralyze resist_turn_undead resist_fear resist_cancellation |
… | |
… | |
93 | sub MOVE_FLY_LOW (){ 0x02 } |
108 | sub MOVE_FLY_LOW (){ 0x02 } |
94 | sub MOVE_FLY_HIGH (){ 0x04 } |
109 | sub MOVE_FLY_HIGH (){ 0x04 } |
95 | sub MOVE_FLYING (){ 0x06 } |
110 | sub MOVE_FLYING (){ 0x06 } |
96 | sub MOVE_SWIM (){ 0x08 } |
111 | sub MOVE_SWIM (){ 0x08 } |
97 | sub MOVE_BOAT (){ 0x10 } |
112 | sub MOVE_BOAT (){ 0x10 } |
|
|
113 | sub MOVE_KNOWN (){ 0x1f } # all of above |
98 | sub MOVE_ALL (){ 0xff } |
114 | sub MOVE_ALLBIT (){ 0x10000 } |
|
|
115 | sub MOVE_ALL (){ 0x1001f } # very special value, more PITA |
99 | |
116 | |
100 | sub load_ref($) { |
117 | sub load_ref($) { |
101 | my ($path) = @_; |
118 | my ($path) = @_; |
102 | |
119 | |
103 | open my $fh, "<", $path |
120 | open my $fh, "<", $path |
… | |
… | |
126 | delete $ob->{$_} for qw( |
143 | delete $ob->{$_} for qw( |
127 | can_knockback can_parry can_impale can_cut can_dam_armour |
144 | can_knockback can_parry can_impale can_cut can_dam_armour |
128 | can_apply pass_thru can_pass_thru |
145 | can_apply pass_thru can_pass_thru |
129 | ); |
146 | ); |
130 | |
147 | |
131 | for my $attr (qw(move_type move_block move_allow move_on move_off move_slow)) { |
148 | for my $attr (keys %FIELD_MOVEMENT) { |
132 | next unless exists $ob->{$attr}; |
149 | next unless exists $ob->{$attr}; |
|
|
150 | |
|
|
151 | $ob->{$attr} = MOVE_ALL if $ob->{$attr} == 255; #d# compatibility |
|
|
152 | |
133 | next if $ob->{$attr} =~ /^\d+$/; |
153 | next if $ob->{$attr} =~ /^\d+$/; |
134 | |
154 | |
135 | my $flags = 0; |
155 | my $flags = 0; |
136 | |
156 | |
137 | # assume list |
157 | # assume list |
… | |
… | |
221 | delete $ob->{$k}; |
241 | delete $ob->{$k}; |
222 | } |
242 | } |
223 | } |
243 | } |
224 | } |
244 | } |
225 | |
245 | |
|
|
246 | # a speciality for the editor |
|
|
247 | if (exists $ob->{attack_movement}) { |
|
|
248 | my $am = delete $ob->{attack_movement}; |
|
|
249 | $ob->{attack_movement_bits_0_3} = $am & 15; |
|
|
250 | $ob->{attack_movement_bits_4_7} = $am & 240; |
|
|
251 | } |
|
|
252 | |
226 | $ob |
253 | $ob |
227 | } |
254 | } |
228 | |
255 | |
229 | sub read_pak($) { |
256 | sub read_pak($) { |
230 | my ($path) = @_; |
257 | my ($path) = @_; |
… | |
… | |
259 | |
286 | |
260 | while (<$fh>) { |
287 | while (<$fh>) { |
261 | s/\s+$//; |
288 | s/\s+$//; |
262 | if (/^end$/i) { |
289 | if (/^end$/i) { |
263 | last; |
290 | last; |
264 | } elsif (/^arch (\S+)$/) { |
291 | } elsif (/^arch (\S+)$/i) { |
265 | push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1); |
292 | push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1); |
266 | } elsif (/^lore$/) { |
293 | } elsif (/^lore$/i) { |
267 | while (<$fh>) { |
294 | while (<$fh>) { |
268 | last if /^endlore\s*$/i; |
295 | last if /^endlore\s*$/i; |
269 | $arc{lore} .= $_; |
296 | $arc{lore} .= $_; |
270 | } |
297 | } |
271 | } elsif (/^msg$/) { |
298 | } elsif (/^msg$/i) { |
272 | while (<$fh>) { |
299 | while (<$fh>) { |
273 | last if /^endmsg\s*$/i; |
300 | last if /^endmsg\s*$/i; |
274 | $arc{msg} .= $_; |
301 | $arc{msg} .= $_; |
275 | } |
302 | } |
276 | } elsif (/^(\S+)\s*(.*)$/) { |
303 | } elsif (/^(\S+)\s*(.*)$/) { |
… | |
… | |
299 | $arc{$name} = $arc; |
326 | $arc{$name} = $arc; |
300 | } |
327 | } |
301 | $prev = $arc; |
328 | $prev = $arc; |
302 | $more = undef; |
329 | $more = undef; |
303 | } elsif (/^arch (\S+)$/i) { |
330 | } elsif (/^arch (\S+)$/i) { |
|
|
331 | my $name = $1; |
304 | push @{ $arc{arch} }, normalize_arch $parse_block->(_name => $1); |
332 | my $arc = normalize_arch $parse_block->(_name => $name); |
|
|
333 | |
|
|
334 | if ($more) { |
|
|
335 | $more->{more} = $arc; |
|
|
336 | } else { |
|
|
337 | push @{ $arc{arch} }, $arc; |
|
|
338 | } |
|
|
339 | $prev = $arc; |
|
|
340 | $more = undef; |
305 | } elsif (/^\s*($|#)/) { |
341 | } elsif (/^\s*($|#)/) { |
306 | # |
342 | # |
307 | } else { |
343 | } else { |
308 | warn "$path: unparseable top-level line '$_'"; |
344 | warn "$path: unparseable top-level line '$_'"; |
309 | } |
345 | } |
… | |
… | |
395 | my $type = $obj->{type} || $arch->{type}; |
431 | my $type = $obj->{type} || $arch->{type}; |
396 | |
432 | |
397 | if ($type > 0) { |
433 | if ($type > 0) { |
398 | $root = $Crossfire::Data::ATTR{$type}; |
434 | $root = $Crossfire::Data::ATTR{$type}; |
399 | } else { |
435 | } else { |
|
|
436 | my %a = (%$arch, %$obj); |
|
|
437 | |
|
|
438 | if ($a{is_floor} && !$a{alive}) { |
|
|
439 | $root = $Crossfire::Data::TYPE{Floor}; |
|
|
440 | } elsif (!$a{is_floor} && $a{alive} && !$a{tear_down}) { |
|
|
441 | $root = $Crossfire::Data::TYPE{"Monster & NPC"}; |
|
|
442 | } elsif (!$a{is_floor} && !$a{alive} && $a{move_block}) { |
|
|
443 | $root = $Crossfire::Data::TYPE{Wall}; |
|
|
444 | } elsif (!$a{is_floor} && $a{alive} && $a{tear_down}) { |
|
|
445 | $root = $Crossfire::Data::TYPE{"Weak Wall"}; |
|
|
446 | } else { |
400 | $root = $Crossfire::Data::TYPE{Misc}; |
447 | $root = $Crossfire::Data::TYPE{Misc}; |
401 | |
|
|
402 | type: |
|
|
403 | for (@Crossfire::Data::ATTR0) { |
|
|
404 | my $req = $_->{required} |
|
|
405 | or die "internal error: ATTR0 without 'required'"; |
|
|
406 | |
|
|
407 | keys %$req; |
|
|
408 | while (my ($k, $v) = each %$req) { |
|
|
409 | next type |
|
|
410 | unless $obj->{$k} == $v || $arch->{$k} == $v; |
|
|
411 | } |
|
|
412 | |
|
|
413 | $root = $_; |
|
|
414 | } |
448 | } |
415 | } |
449 | } |
416 | |
450 | |
417 | my @import = ($root); |
451 | my @import = ($root); |
418 | |
452 | |
… | |
… | |
592 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", sub { |
626 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", sub { |
593 | $TILE = new_from_file Gtk2::Gdk::Pixbuf "$VARDIR/tilecache.png" |
627 | $TILE = new_from_file Gtk2::Gdk::Pixbuf "$VARDIR/tilecache.png" |
594 | or die "$VARDIR/tilecache.png: $!"; |
628 | or die "$VARDIR/tilecache.png: $!"; |
595 | *FACE = $_[0]; |
629 | *FACE = $_[0]; |
596 | }, sub { |
630 | }, sub { |
597 | require File::Temp; |
|
|
598 | |
|
|
599 | my $tile = read_pak "$LIB/crossfire.0"; |
631 | my $tile = read_pak "$LIB/crossfire.0"; |
600 | |
632 | |
601 | my %cache; |
633 | my %cache; |
602 | |
634 | |
603 | my $idx = 0; |
635 | my $idx = 0; |
604 | |
636 | |
605 | for my $name (sort keys %$tile) { |
637 | for my $name (sort keys %$tile) { |
606 | my ($fh, $filename) = File::Temp::tempfile (); |
638 | my $pb = new Gtk2::Gdk::PixbufLoader; |
607 | print $fh $tile->{$name}; |
639 | $pb->write ($tile->{$name}); |
608 | close $fh; |
640 | $pb->close; |
609 | my $pb = new_from_file Gtk2::Gdk::Pixbuf $filename; |
641 | my $pb = $pb->get_pixbuf; |
610 | unlink $filename; |
|
|
611 | |
642 | |
612 | my $tile = $cache{$name} = { |
643 | my $tile = $cache{$name} = { |
613 | pb => $pb, |
644 | pb => $pb, |
614 | idx => $idx, |
645 | idx => $idx, |
615 | w => int $pb->get_width / TILESIZE, |
646 | w => int $pb->get_width / TILESIZE, |
… | |
… | |
633 | $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); |
664 | $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); |
634 | } |
665 | } |
635 | } |
666 | } |
636 | } |
667 | } |
637 | |
668 | |
638 | $pb->save ("$VARDIR/tilecache.png", "png"); |
669 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
639 | |
670 | |
640 | \%cache |
671 | \%cache |
641 | }; |
672 | }; |
642 | } |
673 | } |
643 | |
674 | |