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.24 by root, Tue Nov 3 23:44:21 2009 UTC vs.
Revision 1.38 by root, Sat Nov 17 23:40:02 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4# Copyright (©) 2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5# Copyright (©) 2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 6#
6# Deliantra is free software: you can redistribute it and/or modify it under 7# 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 8# 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 9# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 10# option) any later version.
10# 11#
11# This program is distributed in the hope that it will be useful, 12# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details. 15# GNU General Public License for more details.
15# 16#
16# You should have received a copy of the Affero GNU General Public License 17# You should have received a copy of the Affero GNU General Public License
17# and the GNU General Public License along with this program. If not, see 18# and the GNU General Public License along with this program. If not, see
18# <http://www.gnu.org/licenses/>. 19# <http://www.gnu.org/licenses/>.
19# 20#
20# The authors can be reached via e-mail to <support@deliantra.net> 21# The authors can be reached via e-mail to <support@deliantra.net>
21# 22#
22 23
23=head1 NAME 24=head1 NAME
24 25
34 35
35Match the object if it has a slaying field of C<key1>: 36Match the object if it has a slaying field of C<key1>:
36 37
37 slaying = "key1" 38 slaying = "key1"
38 39
39Match the object if it has an object with name C<force> and 40Match the object if it has an object with name C<force> and
40slaying C<poison> in it's inventory: 41slaying C<poison> in it's inventory:
41 42
42 has (name = "force" and slaying = "poison") 43 has (name = "force" and slaying = "poison")
43 44
44Find all inventory objects with value >= 10, which are not invisible: 45Find all inventory objects with value >= 10, which are not invisible:
229Starts with the default object - this is the object passed to the match to 230Starts 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, 231match 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> 232but submatches start at the current object, and in this case C<of object>
232can be used to start at the original object once more. 233can be used to start at the original object once more.
233 234
235=item of self
236
237Starts with the object initiating/asking for the match - this is basically
238always the object that the match expression is attached to.
239
234=item of source 240=item of source
235 241
236Starts with the I<source> object - this object is sometimes passed to 242Starts with the I<source> object - this object is sometimes passed to
237matches and represents the object that is the source of the action, such 243matches 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 244as 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. 251the original initiator of an action, most commonly a player or monster.
246 252
247This object is often identical to the I<source> (e.g. when a player casts 253This object is often identical to the I<source> (e.g. when a player casts
248a spell, the player is both source and originator). 254a spell, the player is both source and originator).
249 255
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 256=back
256 257
257=head2 EXPRESSIONS 258=head2 EXPRESSIONS
258 259
259Expressions used in conditions usually consist of simple boolean checks 260Expressions used in conditions usually consist of simple boolean checks
268 269
269=item scalar object attributes 270=item scalar object attributes
270 271
271Object attributes that consist of a single value (C<name>, C<title>, 272Object attributes that consist of a single value (C<name>, C<title>,
272C<value> and so on) can be specified by simply using their name, in which 273C<value> and so on) can be specified by simply using their name, in which
273acse their corresponding value is used. 274case their corresponding value is used.
274 275
275=item array objects attributes 276=item array objects attributes
276 277
277The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ] 278The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ]
278>>. 279>>.
282 resist[ATNR_ACID] > 30 283 resist[ATNR_ACID] > 30
283 284
284=item functions 285=item functions
285 286
286Some additional functions with or without arguments in parentheses are 287Some additional functions with or without arguments in parentheses are
287available. 288available. They are documented in their own section, below.
288 289
289=item { BLOCK } 290=item { BLOCK }
290 291
291You can specify perl code to execute by putting it inside curly 292You can specify perl code to execute by putting it inside curly
292braces. The last expression evaluated inside will become the result. 293braces. The last expression evaluated inside will become the result.
331 332
332=item none 333=item none
333 334
334This simply evaluates to false, and simply makes matching I<never> a bit 335This simply evaluates to false, and simply makes matching I<never> a bit
335easier to read. 336easier to read.
337
338=item archname
339
340The same as C<< { $_->arch->archname } >> - the archetype name is commonly
341used to match items, so this shortcut is provided.
342
343=item resist_xxx
344
345Resistancy values such as C<resist_physical>, C<resist_magic>,
346C<resists_fire> etc. are directly available (but can also be accessed via
347array syntax, i.e. C<resists[ATNR_FIRE]>).
348
349=item body_xxx_info and body_xxx_used
350
351Every body location (e.g. C<body_neck_info>, C<body_arm_used> etc.) can
352be accessed via these functions (these are aliases to more cumbersome C<< {
353$_->slot_info (body_xxx) } >> and C<slot_used> method calls).
354
355Example: (e.g. on a door) match only players that have no arms.
356
357 match type=PLAYER and body_arm_info=0
336 358
337=item has(condition) 359=item has(condition)
338 360
339True iff the object has a matching inventory object. 361True iff the object has a matching inventory object.
340 362
459 1 481 1
460 }, 482 },
461 none => sub { 483 none => sub {
462 0 484 0
463 }, 485 },
486 archname => sub {
487 '$_->arch->archname'
488 },
464 ); 489 );
490
491 # resist_xxx
492 for my $atnr (0 .. cf::NROFATTACKS - 1) {
493 $special{"resist_" . cf::attacktype_name ($atnr)} = sub { "\$_->resist ($atnr)" };
494 }
495
496 # body_xxx_info and _used
497 for my $slot (0 .. cf::NUM_BODY_LOCATIONS - 1) {
498 my $name = cf::object::slot_name $slot;
499
500 $special{"body_$name\_info"} = sub { "\$_->slot_info ($slot)" };
501 $special{"body_$name\_used"} = sub { "\$_->slot_used ($slot)" };
502 }
465 503
466 sub constant { 504 sub constant {
467 ws; 505 ws;
468 506
469 return $1 if /\G([\-\+0-9\.]+)/gc; 507 return $1 if /\G([\-\+0-9\.]+)/gc;
714 752
715 $res 753 $res
716} 754}
717 755
718if (0) {#d# 756if (0) {#d#
719 die parse 1, 'stats.pow'; 757 die parse 1, 'type=PLAYER and body_arm_info=0';
720 exit 0; 758 exit 0;
721} 759}
722 760
723our %CACHE; 761our %CACHE;
724 762
725sub compile($$) { 763sub compile($$) {
726 my ($wantarray, $match) = @_; 764 my ($wantarray, $match) = @_;
727 my $expr = parse $wantarray, $match; 765 my $expr = parse $wantarray, $match;
728 warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# 766# warn "MATCH DEBUG $match,$wantarray => $expr\n";#d#
729 $expr = eval " 767 $expr = eval "
730 package cf::match::exec; 768 package cf::match::exec;
731 sub { 769 sub {
732 my (\$object, \$self, \$source, \$originator) = \@_; 770 my (\$object, \$self, \$source, \$originator) = \@_;
733 $expr 771 $expr

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines