|
|
1 | # |
|
|
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | # |
|
|
4 | # Copyright (©) 2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | # |
|
|
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 |
|
|
8 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
9 | # option) any later version. |
|
|
10 | # |
|
|
11 | # This program is distributed in the hope that it will be useful, |
|
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
14 | # GNU General Public License for more details. |
|
|
15 | # |
|
|
16 | # 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 | # <http://www.gnu.org/licenses/>. |
|
|
19 | # |
|
|
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
21 | # |
|
|
22 | |
1 | =head1 NAME |
23 | =head1 NAME |
2 | |
24 | |
3 | cf::match - object matching language |
25 | cf::match - object matching language |
4 | |
26 | |
5 | =head1 DESCRIPTION |
27 | =head1 DESCRIPTION |
… | |
… | |
92 | Not that C<not> only negates a condition and not the whole match |
114 | Not that C<not> only negates a condition and not the whole match |
93 | expressions, thus |
115 | expressions, thus |
94 | |
116 | |
95 | not applied in inv |
117 | not applied in inv |
96 | |
118 | |
97 | is true if there is I<any> non-object in the inventory. To negate a whole |
119 | is true if there is I<any> non-applied object in the inventory. To negate |
98 | match, you have to use a sub-match. To check whether there is I<no> |
120 | a whole match, you have to use a sub-match: To check whether there is |
99 | applied object in someones inventory, write this: |
121 | I<no> applied object in someones inventory, write this: |
100 | |
122 | |
101 | not (applied in inv) |
123 | not (applied in inv) |
102 | |
124 | |
103 | Example: match applied weapons. |
125 | Example: match applied weapons. |
104 | |
126 | |
105 | applied type=WEAPON |
127 | applied type=WEAPON |
106 | |
128 | |
107 | Example: match horns or rods. |
129 | Example: match horns or rods. |
108 | |
130 | |
109 | type=HORN or type=ROD |
131 | type=HORN or type=ROD |
|
|
132 | |
|
|
133 | Example: see if the originator is a player. |
|
|
134 | |
|
|
135 | type=PLAYER of originator |
110 | |
136 | |
111 | =item in ... |
137 | =item in ... |
112 | |
138 | |
113 | The in operator takes the context set and modifies it in various ways. As |
139 | The in operator takes the context set and modifies it in various ways. As |
114 | a less technical description, think of the C<in> as being a I<look into> |
140 | a less technical description, think of the C<in> as being a I<look into> |
… | |
… | |
203 | Starts with the default object - this is the object passed to the match to |
229 | Starts with the default object - this is the object passed to the match to |
204 | match against by default. Matches have an explicit C<of object> appended, |
230 | match against by default. Matches have an explicit C<of object> appended, |
205 | but submatches start at the current object, and in this case C<of object> |
231 | but submatches start at the current object, and in this case C<of object> |
206 | can be used to start at the original object once more. |
232 | can be used to start at the original object once more. |
207 | |
233 | |
|
|
234 | =item of self |
|
|
235 | |
|
|
236 | Starts with the object initiating/asking for the match - this is basically |
|
|
237 | always the object that the match expression is attached to. |
|
|
238 | |
208 | =item of source |
239 | =item of source |
209 | |
240 | |
210 | Starts with the I<source> object - this object is sometimes passed to |
241 | Starts with the I<source> object - this object is sometimes passed to |
211 | matches and represents the object that is the source of the action, such |
242 | matches and represents the object that is the source of the action, such |
212 | as a rod or a potion when it is applied. Often, the I<source> is the same |
243 | as a rod or a potion when it is applied. Often, the I<source> is the same |
… | |
… | |
219 | the original initiator of an action, most commonly a player or monster. |
250 | the original initiator of an action, most commonly a player or monster. |
220 | |
251 | |
221 | This object is often identical to the I<source> (e.g. when a player casts |
252 | This object is often identical to the I<source> (e.g. when a player casts |
222 | a spell, the player is both source and originator). |
253 | a spell, the player is both source and originator). |
223 | |
254 | |
224 | =item of self |
|
|
225 | |
|
|
226 | Starts with the object initiating/asking for the match - this is basically |
|
|
227 | always the object that the match expression is attached to. |
|
|
228 | |
|
|
229 | =back |
255 | =back |
230 | |
256 | |
231 | =head2 EXPRESSIONS |
257 | =head2 EXPRESSIONS |
232 | |
258 | |
233 | Expressions used in conditions usually consist of simple boolean checks |
259 | Expressions used in conditions usually consist of simple boolean checks |
… | |
… | |
242 | |
268 | |
243 | =item scalar object attributes |
269 | =item scalar object attributes |
244 | |
270 | |
245 | Object attributes that consist of a single value (C<name>, C<title>, |
271 | Object attributes that consist of a single value (C<name>, C<title>, |
246 | C<value> and so on) can be specified by simply using their name, in which |
272 | C<value> and so on) can be specified by simply using their name, in which |
247 | acse their corresponding value is used. |
273 | case their corresponding value is used. |
248 | |
274 | |
249 | =item array objects attributes |
275 | =item array objects attributes |
250 | |
276 | |
251 | The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ] |
277 | The C<resist> array can be accessed by specifying C<< resist [ ATNR_type ] |
252 | >>. |
278 | >>. |
… | |
… | |
256 | resist[ATNR_ACID] > 30 |
282 | resist[ATNR_ACID] > 30 |
257 | |
283 | |
258 | =item functions |
284 | =item functions |
259 | |
285 | |
260 | Some additional functions with or without arguments in parentheses are |
286 | Some additional functions with or without arguments in parentheses are |
261 | available. |
287 | available. They are documented in their own section, below. |
262 | |
288 | |
263 | =item { BLOCK } |
289 | =item { BLOCK } |
264 | |
290 | |
265 | You can specify perl code to execute by putting it inside curly |
291 | You can specify perl code to execute by putting it inside curly |
266 | braces. The last expression evaluated inside will become the result. |
292 | braces. The last expression evaluated inside will become the result. |
… | |
… | |
305 | |
331 | |
306 | =item none |
332 | =item none |
307 | |
333 | |
308 | This simply evaluates to false, and simply makes matching I<never> a bit |
334 | This simply evaluates to false, and simply makes matching I<never> a bit |
309 | easier to read. |
335 | easier to read. |
|
|
336 | |
|
|
337 | =item archname |
|
|
338 | |
|
|
339 | The same as C<< { $_->arch->archname } >> - the archetype name is commonly |
|
|
340 | used to match items, so this shortcut is provided. |
|
|
341 | |
|
|
342 | =item resist_xxx |
|
|
343 | |
|
|
344 | Resistancy values such as C<resist_physical>, C<resist_magic>, |
|
|
345 | C<resists_fire> etc. are directly available (but can also be accessed via |
|
|
346 | array syntax, i.e. C<resists[ATNR_FIRE]>). |
|
|
347 | |
|
|
348 | =item body_xxx_info and body_xxx_used |
|
|
349 | |
|
|
350 | Every body location (e.g. C<body_neck_info>, C<body_arm_used> etc.) can |
|
|
351 | be accessed via these functions (these are aliases to more cumbersome C<< { |
|
|
352 | $_->slot_info (body_xxx) } >> and C<slot_used> method calls). |
|
|
353 | |
|
|
354 | Example: (e.g. on a door) match only players that have no arms. |
|
|
355 | |
|
|
356 | match type=PLAYER and body_arm_info=0 |
310 | |
357 | |
311 | =item has(condition) |
358 | =item has(condition) |
312 | |
359 | |
313 | True iff the object has a matching inventory object. |
360 | True iff the object has a matching inventory object. |
314 | |
361 | |
… | |
… | |
433 | 1 |
480 | 1 |
434 | }, |
481 | }, |
435 | none => sub { |
482 | none => sub { |
436 | 0 |
483 | 0 |
437 | }, |
484 | }, |
|
|
485 | archname => sub { |
|
|
486 | '$_->arch->archname' |
|
|
487 | }, |
438 | ); |
488 | ); |
|
|
489 | |
|
|
490 | # resist_xxx |
|
|
491 | for my $atnr (0 .. cf::NROFATTACKS - 1) { |
|
|
492 | $special{"resist_" . cf::attacktype_name ($atnr)} = sub { "\$_->resist ($atnr)" }; |
|
|
493 | } |
|
|
494 | |
|
|
495 | # body_xxx_info and _used |
|
|
496 | for my $slot (0 .. cf::NUM_BODY_LOCATIONS - 1) { |
|
|
497 | my $name = cf::object::slot_name $slot; |
|
|
498 | |
|
|
499 | $special{"body_$name\_info"} = sub { "\$_->slot_info ($slot)" }; |
|
|
500 | $special{"body_$name\_used"} = sub { "\$_->slot_used ($slot)" }; |
|
|
501 | } |
439 | |
502 | |
440 | sub constant { |
503 | sub constant { |
441 | ws; |
504 | ws; |
442 | |
505 | |
443 | return $1 if /\G([\-\+0-9\.]+)/gc; |
506 | return $1 if /\G([\-\+0-9\.]+)/gc; |
… | |
… | |
688 | |
751 | |
689 | $res |
752 | $res |
690 | } |
753 | } |
691 | |
754 | |
692 | if (0) {#d# |
755 | if (0) {#d# |
693 | die parse 1, 'stats.pow'; |
756 | die parse 1, 'type=PLAYER and body_arm_info=0'; |
694 | exit 0; |
757 | exit 0; |
695 | } |
758 | } |
696 | |
759 | |
697 | our %CACHE; |
760 | our %CACHE; |
698 | |
761 | |
699 | sub compile($$) { |
762 | sub compile($$) { |
700 | my ($wantarray, $match) = @_; |
763 | my ($wantarray, $match) = @_; |
701 | my $expr = parse $wantarray, $match; |
764 | my $expr = parse $wantarray, $match; |
702 | warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# |
765 | # warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# |
703 | $expr = eval " |
766 | $expr = eval " |
704 | package cf::match::exec; |
767 | package cf::match::exec; |
705 | sub { |
768 | sub { |
706 | my (\$object, \$self, \$source, \$originator) = \@_; |
769 | my (\$object, \$self, \$source, \$originator) = \@_; |
707 | $expr |
770 | $expr |