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.13 by root, Thu Feb 9 20:54:42 2006 UTC vs.
Revision 1.16 by root, Tue Feb 21 21:37:01 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",
36 lore => "endlore",
35); 37);
36 38
37# not used yet, maybe alphabetical is ok 39# not used yet, maybe alphabetical is ok
38our @FIELD_ORDER = (qw(name name_pl)); 40our @FIELD_ORDER = (qw(name name_pl));
39 41
40# not used yet, AND NOT CHECKED, should also be BY TYPE 42sub MOVE_WALK (){ 0x1 }
41our %FIELD_NORMALIZE = ( 43sub MOVE_FLY_LOW (){ 0x2 }
44sub MOVE_FLY_HIGH (){ 0x4 }
45sub MOVE_FLYING (){ 0x6 }
46sub MOVE_SWIM (){ 0x8 }
47sub MOVE_ALL (){ 0xf }
48
49sub normalize_arch($) {
50 my ($ob) = @_;
51
52 my $arch = $ARCH{$ob->{_name}}
53 or (warn "$ob->{_name}: no such archetype", return $ob);
54
55 delete $ob->{$_} for qw(can_knockback can_parry can_impale can_cut can_dam_armour can_apply);
56
57 if ($arch->{type} == 22) { # map
58 my %normalize = (
42 "enter_x" => "hp", 59 "enter_x" => "hp",
43 "enter_y" => "sp", 60 "enter_y" => "sp",
44); 61 "width" => "x",
62 "height" => "y",
63 "reset_timeout" => "weight",
64 "swap_time" => "value",
65 "difficulty" => "level",
66 "darkness" => "invisible",
67 "fixed_resettime" => "stand_still",
68 );
69
70 while (my ($k2, $k1) = each %normalize) {
71 if (defined (my $v = delete $ob->{$k1})) {
72 $ob->{$k2} = $v;
73 }
74 }
75 }
76
77 if (defined (my $v = delete $ob->{no_pass})) {
78 $ob->{move_block} = $v ? MOVE_ALL : 0;
79 }
80 if (defined (my $v = delete $ob->{walk_on})) {
81 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK
82 : $ob->{move_on} & ~MOVE_WALK;
83 }
84 if (defined (my $v = delete $ob->{walk_off})) {
85 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK
86 : $ob->{move_off} & ~MOVE_WALK;
87 }
88 if (defined (my $v = delete $ob->{fly_on})) {
89 $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW
90 : $ob->{move_on} & ~MOVE_FLY_LOW;
91 }
92 if (defined (my $v = delete $ob->{fly_off})) {
93 $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW
94 : $ob->{move_off} & ~MOVE_FLY_LOW;
95 }
96 if (defined (my $v = delete $ob->{flying})) {
97 $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW
98 : $ob->{move_type} & ~MOVE_FLY_LOW;
99 }
100
101 # if value matches archetype default, delete
102 while (my ($k, $v) = each %$ob) {
103 if (exists $arch->{$k} and $arch->{$k} eq $v) {
104 next if $k eq "_name";
105 delete $ob->{$k};
106 }
107 }
108
109 $ob
110}
45 111
46sub read_pak($;$) { 112sub read_pak($;$) {
47 my ($path, $cache) = @_; 113 my ($path, $cache) = @_;
48 114
49 eval { 115 eval {
88 while (<$fh>) { 154 while (<$fh>) {
89 s/\s+$//; 155 s/\s+$//;
90 if (/^end$/i) { 156 if (/^end$/i) {
91 last; 157 last;
92 } elsif (/^arch (\S+)$/) { 158 } elsif (/^arch (\S+)$/) {
93 push @{ $arc{inventory} }, $parse_block->(_name => $1); 159 push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1);
94 } elsif (/^lore$/) { 160 } elsif (/^lore$/) {
95 while (<$fh>) { 161 while (<$fh>) {
96 last if /^endlore\s*$/i; 162 last if /^endlore\s*$/i;
97 $arc{lore} .= $_; 163 $arc{lore} .= $_;
98 } 164 }
127 $arc{$name} = $arc; 193 $arc{$name} = $arc;
128 } 194 }
129 $prev = $arc; 195 $prev = $arc;
130 $more = undef; 196 $more = undef;
131 } elsif (/^arch (\S+)$/i) { 197 } elsif (/^arch (\S+)$/i) {
132 push @{ $arc{arch} }, $parse_block->(_name => $1); 198 push @{ $arc{arch} }, normalize_arch $parse_block->(_name => $1);
133 } elsif (/^\s*($|#)/) { 199 } elsif (/^\s*($|#)/) {
134 # 200 #
135 } else { 201 } else {
136 warn "$path: unparseable top-level line '$_'"; 202 warn "$path: unparseable top-level line '$_'";
137 } 203 }
144 210
145 \%arc 211 \%arc
146 } 212 }
147} 213}
148 214
149# returns the arch/object stack from a tile on a map
150sub map_get_tile_stack {
151 my ($map, $x, $y) = @_;
152 my $as;
153
154 if ($x > 0 || $x < $map->{width}
155 || $y > 0 || $y < $map->{height}) {
156
157 $as = $map->{map}{map}[$x][$y] || [];
158 }
159
160 return $as;
161}
162
163# pop the topmost arch/object from the stack of a tile on a map
164sub map_pop_tile_stack {
165 my ($map, $x, $y) = @_;
166
167 if ($x > 0 || $x < $map->{width}
168 || $y > 0 || $y < $map->{height}) {
169
170 pop @{$map->{map}{map}[$x][$y]};
171 }
172}
173
174# pushes the arch/object on the stack of a tile on a map
175sub map_push_tile_stack {
176 my ($map, $x, $y, $arch) = @_;
177
178 if ($x > 0 || $x < $map->{width}
179 || $y > 0 || $y < $map->{height}) {
180
181 push @{$map->{map}{map}[$x][$y]}, $arch;
182 }
183}
184
185
186# 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
187# NOTE: the arrays in the hash values are references to 216# NOTE: the arrays in the hash values are references to
188# the archs from $ARCH 217# the archs from $ARCH
189sub editor_archs { 218sub editor_archs {
190 my %paths; 219 my %paths;
191 220
192 for (keys %$ARCH) { 221 for (keys %ARCH) {
193 my $arch = $ARCH->{$_}; 222 my $arch = $ARCH{$_};
194 push @{$paths{$arch->{editor_folder}}}, \$arch; 223 push @{$paths{$arch->{editor_folder}}}, \$arch;
195 } 224 }
196 225
197 return \%paths; 226 \%paths
198} 227}
199 228
200# arch_extends determines how the arch looks like on the map, 229# arch_extents determines the extents of a given arch
201# bigfaces, linked faces and single faces are handled here 230# bigfaces, linked faces and single faces are handled here
202# it returns (<xoffset>, <yoffset>, <width>, <height>) 231# it returns (minx, miny, maxx, maxy)
203# NOTE: non rectangular linked faces are not considered
204sub arch_extends { 232sub arch_extents {
205 my ($a) = @_; 233 my ($a) = @_;
206 234
207 my $TC = \%Crossfire::Tilecache::TILECACHE; 235 my $o = $ARCH{$a->{_name}}
208
209 my $facename =
210 $a->{face} || $ARCH->{$a->{_name}}->{face}
211 or return (); 236 or return;
212 237
213 my $tile = $TC->{$facename} 238 my $face = $FACE{$a->{face} || $o->{face}}
214 or (warn "no gfx found for arch '$facename' in arch_size ()"), return; 239 or (warn "no face data found for arch '$a->{_name}'"), return;
215 240
216 if ($tile->{w} > 1 || $tile->{h} > 1) { 241 if ($face->{w} > 1 || $face->{h} > 1) {
217 # bigfaces 242 # bigface
218 return (0, 0, $tile->{w}, $tile->{h}); 243 return (0, 0, $face->{w} - 1, $face->{h} - 1);
219 244
220 } elsif ($a->{more}) { 245 } elsif ($o->{more}) {
221 # linked faces 246 # linked face
222 my ($miw, $mih, $maw, $mah) = (0, 0, 0, 0); 247 my ($minx, $miny, $maxx, $maxy) = ($o->{x}, $o->{y}) x 2;
223 do {
224 $miw > (0 + $a->{x}) and $miw = $a->{x};
225 $mih > (0 + $a->{y}) and $mih = $a->{y};
226 $maw < (0 + $a->{x}) and $maw = $a->{x};
227 $mah < (0 + $a->{y}) and $mah = $a->{y};
228 } while $a = $a->{more};
229 248
230 return ($miw, $mih, ($maw - $miw) + 1, ($mah - $mih) + 1) 249 for (; $o; $o = $o->{more}) {
250 $minx = min $minx, $o->{x};
251 $miny = min $miny, $o->{y};
252 $maxx = max $maxx, $o->{x};
253 $maxy = max $maxy, $o->{y};
254 }
255
256 return ($minx, $miny, $maxx, $maxy);
231 257
232 } else { 258 } else {
233 # single face 259 # single face
234 return (0, 0, 1, 1); 260 return (0, 0, 0, 0);
235 } 261 }
236} 262}
237 263
238sub init($) { 264sub init($) {
239 my ($cachedir) = @_; 265 my ($cachedir) = @_;
240 266
267 return if %ARCH;
268
241 $ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 269 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
242} 270}
271
272sub arch_edit_sections {
273# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
274# edit_type = 0;
275# else if (edit_type != 0) {
276# // all flags from 'check_type' must be unset in this arch because they get recalculated now
277# edit_type &= ~check_type;
278# }
279#
280# }
281# if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 &&
282# getAttributeValue("alive", defarch) == 1 &&
283# (getAttributeValue("monster", defarch) == 1 ||
284# getAttributeValue("generator", defarch) == 1)) {
285# // Monster: monsters/npcs/generators
286# edit_type |= IGUIConstants.TILE_EDIT_MONSTER;
287# }
288# if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 &&
289# arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) {
290# // Walls
291# edit_type |= IGUIConstants.TILE_EDIT_WALL;
292# }
293# if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 &&
294# getAttributeValue("connected", defarch) != 0) {
295# // Connected Objects
296# edit_type |= IGUIConstants.TILE_EDIT_CONNECTED;
297# }
298# if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 &&
299# arch_type == 66 || arch_type == 41 || arch_type == 95) {
300# // Exit: teleporter/exit/trapdoors
301# edit_type |= IGUIConstants.TILE_EDIT_EXIT;
302# }
303# if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 &&
304# getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 ||
305# arch_type == 5 || arch_type == 36 || arch_type == 60 ||
306# arch_type == 85 || arch_type == 111 || arch_type == 123 ||
307# arch_type == 124 || arch_type == 130)) {
308# // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls
309# edit_type |= IGUIConstants.TILE_EDIT_TREASURE;
310# }
311# if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 &&
312# arch_type == 20 || arch_type == 23 || arch_type == 26 ||
313# arch_type == 91 || arch_type == 21 || arch_type == 24) {
314# // Door: door/special door/gates + keys
315# edit_type |= IGUIConstants.TILE_EDIT_DOOR;
316# }
317# if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 &&
318# getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 &&
319# arch_type <= 16) || arch_type == 33 || arch_type == 34 ||
320# arch_type == 35 || arch_type == 39 || arch_type == 70 ||
321# arch_type == 87 || arch_type == 99 || arch_type == 100 ||
322# arch_type == 104 || arch_type == 109 || arch_type == 113 ||
323# arch_type == 122 || arch_type == 3)) {
324# // Equipment: weapons/armour/wands/rods
325# edit_type |= IGUIConstants.TILE_EDIT_EQUIP;
326# }
327#
328# return(edit_type);
329#
330#
331}
332
333$CACHEDIR ||= "$ENV{HOME}/.crossfire";
334
335init $CACHEDIR;
243 336
244=head1 AUTHOR 337=head1 AUTHOR
245 338
246 Marc Lehmann <schmorp@schmorp.de> 339 Marc Lehmann <schmorp@schmorp.de>
247 http://home.schmorp.de/ 340 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines