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. |
… | |
… | |
229 | 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 |
230 | 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, |
231 | 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> |
232 | can be used to start at the original object once more. |
232 | can be used to start at the original object once more. |
233 | |
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 | |
234 | =item of source |
239 | =item of source |
235 | |
240 | |
236 | 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 |
237 | 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 |
238 | 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 |
… | |
… | |
245 | 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. |
246 | |
251 | |
247 | 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 |
248 | a spell, the player is both source and originator). |
253 | a spell, the player is both source and originator). |
249 | |
254 | |
250 | =item of self |
|
|
251 | |
|
|
252 | Starts with the object initiating/asking for the match - this is basically |
|
|
253 | always the object that the match expression is attached to. |
|
|
254 | |
|
|
255 | =back |
255 | =back |
256 | |
256 | |
257 | =head2 EXPRESSIONS |
257 | =head2 EXPRESSIONS |
258 | |
258 | |
259 | Expressions used in conditions usually consist of simple boolean checks |
259 | Expressions used in conditions usually consist of simple boolean checks |
… | |
… | |
268 | |
268 | |
269 | =item scalar object attributes |
269 | =item scalar object attributes |
270 | |
270 | |
271 | 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>, |
272 | 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 |
273 | acse their corresponding value is used. |
273 | case their corresponding value is used. |
274 | |
274 | |
275 | =item array objects attributes |
275 | =item array objects attributes |
276 | |
276 | |
277 | 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 ] |
278 | >>. |
278 | >>. |
… | |
… | |
282 | resist[ATNR_ACID] > 30 |
282 | resist[ATNR_ACID] > 30 |
283 | |
283 | |
284 | =item functions |
284 | =item functions |
285 | |
285 | |
286 | Some additional functions with or without arguments in parentheses are |
286 | Some additional functions with or without arguments in parentheses are |
287 | available. |
287 | available. They are documented in their own section, below. |
288 | |
288 | |
289 | =item { BLOCK } |
289 | =item { BLOCK } |
290 | |
290 | |
291 | 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 |
292 | braces. The last expression evaluated inside will become the result. |
292 | braces. The last expression evaluated inside will become the result. |
… | |
… | |
331 | |
331 | |
332 | =item none |
332 | =item none |
333 | |
333 | |
334 | 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 |
335 | 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 acessed 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 |
336 | |
357 | |
337 | =item has(condition) |
358 | =item has(condition) |
338 | |
359 | |
339 | True iff the object has a matching inventory object. |
360 | True iff the object has a matching inventory object. |
340 | |
361 | |
… | |
… | |
459 | 1 |
480 | 1 |
460 | }, |
481 | }, |
461 | none => sub { |
482 | none => sub { |
462 | 0 |
483 | 0 |
463 | }, |
484 | }, |
|
|
485 | archname => sub { |
|
|
486 | '$_->arch->archname' |
|
|
487 | }, |
464 | ); |
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 | } |
465 | |
502 | |
466 | sub constant { |
503 | sub constant { |
467 | ws; |
504 | ws; |
468 | |
505 | |
469 | return $1 if /\G([\-\+0-9\.]+)/gc; |
506 | return $1 if /\G([\-\+0-9\.]+)/gc; |
… | |
… | |
475 | die "number, string or uppercase constant name expected\n"; |
512 | die "number, string or uppercase constant name expected\n"; |
476 | } |
513 | } |
477 | |
514 | |
478 | our $flag = $cf::REFLECT{object}{flags}; |
515 | our $flag = $cf::REFLECT{object}{flags}; |
479 | our $sattr = $cf::REFLECT{object}{scalars}; |
516 | our $sattr = $cf::REFLECT{object}{scalars}; |
480 | # quick hack to support archname, untested |
|
|
481 | $sattr->{archname} = "W"; |
|
|
482 | our $aattr = $cf::REFLECT{object}{arrays}; |
517 | our $aattr = $cf::REFLECT{object}{arrays}; |
483 | our $lattr = $cf::REFLECT{living}{scalars}; |
518 | our $lattr = $cf::REFLECT{living}{scalars}; |
484 | |
519 | |
485 | sub expr { |
520 | sub expr { |
486 | # ws done by factor |
521 | # ws done by factor |
… | |
… | |
716 | |
751 | |
717 | $res |
752 | $res |
718 | } |
753 | } |
719 | |
754 | |
720 | if (0) {#d# |
755 | if (0) {#d# |
721 | die parse 1, 'stats.pow'; |
756 | die parse 1, 'type=PLAYER and body_arm_info=0'; |
722 | exit 0; |
757 | exit 0; |
723 | } |
758 | } |
724 | |
759 | |
725 | our %CACHE; |
760 | our %CACHE; |
726 | |
761 | |
727 | sub compile($$) { |
762 | sub compile($$) { |
728 | my ($wantarray, $match) = @_; |
763 | my ($wantarray, $match) = @_; |
729 | my $expr = parse $wantarray, $match; |
764 | my $expr = parse $wantarray, $match; |
730 | warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# |
765 | # warn "MATCH DEBUG $match,$wantarray => $expr\n";#d# |
731 | $expr = eval " |
766 | $expr = eval " |
732 | package cf::match::exec; |
767 | package cf::match::exec; |
733 | sub { |
768 | sub { |
734 | my (\$object, \$self, \$source, \$originator) = \@_; |
769 | my (\$object, \$self, \$source, \$originator) = \@_; |
735 | $expr |
770 | $expr |