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.20 by root, Tue Oct 20 05:57:08 2009 UTC vs.
Revision 1.22 by root, Sat Oct 24 11:45:40 2009 UTC

136 136
137=item in map 137=item in map
138 138
139Replaces all objects by the objects that are on the same mapspace as them. 139Replaces all objects by the objects that are on the same mapspace as them.
140 140
141=item in head
142
143Replaces all objects by their head objects.
144
141=item in <condition> 145=item in <condition>
142 146
143Finds all context objects matching the condition, and then puts their 147Finds all context objects matching the condition, and then puts their
144inventories into the context set. 148inventories into the context set.
145 149
297=item any 301=item any
298 302
299This simply evaluates to true, and simply makes matching I<any> object a 303This simply evaluates to true, and simply makes matching I<any> object a
300bit easier to read. 304bit easier to read.
301 305
306=item none
307
308This simply evaluates to false, and simply makes matching I<never> a bit
309easier to read.
310
302=item has(condition) 311=item has(condition)
303 312
304True iff the object has a matching inventory object. 313True iff the object has a matching inventory object.
305 314
306=item count(match) 315=item count(match)
330 339
331 match = chain 340 match = chain
332 | chain 'of' root 341 | chain 'of' root
333 root = 'object' | 'self' | 'source' | 'originator' 342 root = 'object' | 'self' | 'source' | 'originator'
334 chain = condition 343 chain = condition
335 | chain also deep 'in' set 344 | chain also deep 'in' modifier
336 also = nothing | 'also' 345 also = nothing | 'also'
337 deep = nothing | 'deep' 346 deep = nothing | 'deep'
338 set = 'inv' | 'env' | 'arch' | 'map' 347 modifier ='inv' | 'env' | 'arch' | 'map' | 'head'
339 348
340 empty = 349 nothing =
341 350
342 # boolean matching condition 351 # boolean matching condition
343 352
344 condition = factor 353 condition = factor
345 | factor 'and'? condition 354 | factor 'and'? condition
353 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>=' 362 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>='
354 363
355 expr = flag 364 expr = flag
356 | sattr 365 | sattr
357 | aattr '[' <constant> ']' 366 | aattr '[' <constant> ']'
367 | 'stat.' statattr
358 | special 368 | special
359 | func '(' args ')' 369 | func '(' args ')'
360 | '{' perl code block '}' 370 | '{' perl code block '}'
361 371
362 func = <any function name> 372 func = <any function name>
363 sattr = <any scalar object attribute> 373 sattr = <any scalar object attribute>
364 aattr = <any array object attribute> 374 aattr = <any array object attribute>
365 flag = <any object flag> 375 flag = <any object flag>
376 statattr = <any stat attribute: exp, food, str, dex, hp, maxhp...>
366 special = <any ()-less "function"> 377 special = <any ()-less "function">
367 378
368 constant = <number> | '"' <string> '"' | <uppercase cf::XXX name> 379 constant = <number> | '"' <string> '"' | <uppercase cf::XXX name>
369 args = <depends on function> 380 args = <depends on function>
370 381
419 430
420 our %special = ( 431 our %special = (
421 any => sub { 432 any => sub {
422 1 433 1
423 }, 434 },
435 none => sub {
436 0
437 },
424 ); 438 );
425 439
426 sub constant { 440 sub constant {
427 ws; 441 ws;
428 442
436 } 450 }
437 451
438 our $flag = $cf::REFLECT{object}{flags}; 452 our $flag = $cf::REFLECT{object}{flags};
439 our $sattr = $cf::REFLECT{object}{scalars}; 453 our $sattr = $cf::REFLECT{object}{scalars};
440 our $aattr = $cf::REFLECT{object}{arrays}; 454 our $aattr = $cf::REFLECT{object}{arrays};
455 our $lattr = $cf::REFLECT{living}{scalars};
441 456
442 sub expr { 457 sub expr {
443 # ws done by factor 458 # ws done by factor
444 my $res; 459 my $res;
445 460
447 # perl 462 # perl
448 463
449 my $expr = $1; 464 my $expr = $1;
450 465
451 $res .= $expr =~ /\{([^;]+)\}/ ? $1 : "do $expr"; 466 $res .= $expr =~ /\{([^;]+)\}/ ? $1 : "do $expr";
467
468 } elsif (/\Gstats\.([A-Za-z0-9_]+)/gc) {
469
470 if (exists $lattr->{$1}) {
471 $res .= "\$_->stats->$1";
472 } elsif (exists $lattr->{"\u$1"}) {
473 $res .= "\$_->stats->\u$1";
474 } else {
475 die "living statistic name expected (str, pow, hp, sp...)\n";
476 }
452 477
453 } elsif (/\G([A-Za-z0-9_]+)/gc) { 478 } elsif (/\G([A-Za-z0-9_]+)/gc) {
454 479
455 if (my $func = $func{$1}) { 480 if (my $func = $func{$1}) {
456 /\G\s*\(/gc 481 /\G\s*\(/gc
568 my $res = condition; 593 my $res = condition;
569 594
570 # if nothing follows, we have a simple condition, so 595 # if nothing follows, we have a simple condition, so
571 # optimise a comon case. 596 # optimise a comon case.
572 if ($defctx eq '$_' and /\G\s*(?=\)|$)/gc) { 597 if ($defctx eq '$_' and /\G\s*(?=\)|$)/gc) {
573 warn "shortcut<$res>$wantarray\n";#d#
574 return $wantarray 598 return $wantarray
575 ? "$res ? \$_ : ()" 599 ? "$res ? \$_ : ()"
576 : $res; 600 : $res;
577 } 601 }
578 602
585 my $deep = /\Gdeep\s+/gc + 0; 609 my $deep = /\Gdeep\s+/gc + 0;
586 610
587 if (/\Gin\s+/gc) { 611 if (/\Gin\s+/gc) {
588 my $expand; 612 my $expand;
589 613
590 if (/\G(inv|env|map|arch)\b/gc) { 614 if (/\G(inv|env|map|arch|head)\b/gc) {
591 if ($1 eq "inv") { 615 if ($1 eq "inv") {
592 $expand = "map \$_->inv,"; 616 $expand = "map \$_->inv,";
593 } elsif ($1 eq "env") { 617 } elsif ($1 eq "env") {
594 $expand = "map \$_->env // (),"; 618 $expand = "map \$_->env // (),";
619 } elsif ($1 eq "head") {
620 $expand = "map \$_->head,";
621 $deep = 0; # infinite loop otherwise
595 } elsif ($1 eq "arch") { 622 } elsif ($1 eq "arch") {
596 $expand = "map \$_->arch,"; 623 $expand = "map \$_->arch,";
597 $deep = 0; # infinite loop otherwise 624 $deep = 0; # infinite loop otherwise
598 } elsif ($1 eq "map") { 625 } elsif ($1 eq "map") {
599 $expand = "map \$_->map->at (\$_->x, \$_->y),"; 626 $expand = "map \$_->map->at (\$_->x, \$_->y),";
661 688
662 $res 689 $res
663} 690}
664 691
665if (0) {#d# 692if (0) {#d#
666 die parse 1, 'applied in inv'; 693 die parse 1, 'stats.pow';
667 exit 0; 694 exit 0;
668} 695}
669 696
670our %CACHE; 697our %CACHE;
671 698

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines