ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/match.pm
(Generate patch)

Comparing deliantra/server/lib/cf/match.pm (file contents):
Revision 1.25 by root, Sat Mar 20 20:26:18 2010 UTC vs.
Revision 1.29 by root, Sat Aug 28 00:30:29 2010 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
229Starts with the default object - this is the object passed to the match to 229Starts with the default object - this is the object passed to the match to
230match against by default. Matches have an explicit C<of object> appended, 230match against by default. Matches have an explicit C<of object> appended,
231but submatches start at the current object, and in this case C<of object> 231but submatches start at the current object, and in this case C<of object>
232can be used to start at the original object once more. 232can be used to start at the original object once more.
233 233
234=item of self
235
236Starts with the object initiating/asking for the match - this is basically
237always the object that the match expression is attached to.
238
234=item of source 239=item of source
235 240
236Starts with the I<source> object - this object is sometimes passed to 241Starts with the I<source> object - this object is sometimes passed to
237matches and represents the object that is the source of the action, such 242matches and represents the object that is the source of the action, such
238as a rod or a potion when it is applied. Often, the I<source> is the same 243as a rod or a potion when it is applied. Often, the I<source> is the same
245the original initiator of an action, most commonly a player or monster. 250the original initiator of an action, most commonly a player or monster.
246 251
247This object is often identical to the I<source> (e.g. when a player casts 252This object is often identical to the I<source> (e.g. when a player casts
248a spell, the player is both source and originator). 253a spell, the player is both source and originator).
249 254
250=item of self
251
252Starts with the object initiating/asking for the match - this is basically
253always the object that the match expression is attached to.
254
255=back 255=back
256 256
257=head2 EXPRESSIONS 257=head2 EXPRESSIONS
258 258
259Expressions used in conditions usually consist of simple boolean checks 259Expressions used in conditions usually consist of simple boolean checks
282 resist[ATNR_ACID] > 30 282 resist[ATNR_ACID] > 30
283 283
284=item functions 284=item functions
285 285
286Some additional functions with or without arguments in parentheses are 286Some additional functions with or without arguments in parentheses are
287available. 287available. They are documented in their own section, below.
288 288
289=item { BLOCK } 289=item { BLOCK }
290 290
291You can specify perl code to execute by putting it inside curly 291You can specify perl code to execute by putting it inside curly
292braces. The last expression evaluated inside will become the result. 292braces. The last expression evaluated inside will become the result.
331 331
332=item none 332=item none
333 333
334This simply evaluates to false, and simply makes matching I<never> a bit 334This simply evaluates to false, and simply makes matching I<never> a bit
335easier to read. 335easier to read.
336
337=item archname
338
339The same as C<< { $_->arch->archname } >> - the archetype name is commonly
340used to match items, so this shortcut is provided.
336 341
337=item has(condition) 342=item has(condition)
338 343
339True iff the object has a matching inventory object. 344True iff the object has a matching inventory object.
340 345
459 1 464 1
460 }, 465 },
461 none => sub { 466 none => sub {
462 0 467 0
463 }, 468 },
469 archname => sub {
470 '$_->arch->archname'
471 },
464 ); 472 );
465 473
466 sub constant { 474 sub constant {
467 ws; 475 ws;
468 476
475 die "number, string or uppercase constant name expected\n"; 483 die "number, string or uppercase constant name expected\n";
476 } 484 }
477 485
478 our $flag = $cf::REFLECT{object}{flags}; 486 our $flag = $cf::REFLECT{object}{flags};
479 our $sattr = $cf::REFLECT{object}{scalars}; 487 our $sattr = $cf::REFLECT{object}{scalars};
480 # quick hack to support archname, untested
481 $sattr->{archname} = "W";
482 our $aattr = $cf::REFLECT{object}{arrays}; 488 our $aattr = $cf::REFLECT{object}{arrays};
483 our $lattr = $cf::REFLECT{living}{scalars}; 489 our $lattr = $cf::REFLECT{living}{scalars};
484 490
485 sub expr { 491 sub expr {
486 # ws done by factor 492 # ws done by factor
725our %CACHE; 731our %CACHE;
726 732
727sub compile($$) { 733sub compile($$) {
728 my ($wantarray, $match) = @_; 734 my ($wantarray, $match) = @_;
729 my $expr = parse $wantarray, $match; 735 my $expr = parse $wantarray, $match;
730 warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# 736# warn "MATCH DEBUG $match,$wantarray => $expr\n";#d#
731 $expr = eval " 737 $expr = eval "
732 package cf::match::exec; 738 package cf::match::exec;
733 sub { 739 sub {
734 my (\$object, \$self, \$source, \$originator) = \@_; 740 my (\$object, \$self, \$source, \$originator) = \@_;
735 $expr 741 $expr

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines