Inform - Support - Source

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

Identical (lines 2732-2787)

2732  !  Identical decides whether or not two objects can be distinguished from
2733  !  each other by anything the player can type.  If not, it returns true.
2734  ! ----------------------------------------------------------------------------
2735   
2736  [ Identical o1 o2 p1 p2 n1 n2 i j flag;
2737   
2738    if (o1==o2) rtrue;  ! This should never happen, but to be on the safe side
2739    if (o1==0 || o2==0) rfalse;  ! Similarly
2740    if (parent(o1)==compass || parent(o2)==compass) rfalse; ! Saves time
2741   
2742  !  What complicates things is that o1 or o2 might have a parsing routine,
2743  !  so the parser can't know from here whether they are or aren't the same.
2744  !  If they have different parsing routines, we simply assume they're
2745  !  different.  If they have the same routine (which they probably got from
2746  !  a class definition) then the decision process is as follows:
2747  !
2748  !     the routine is called (with self being o1, not that it matters)
2749  !       with noun and second being set to o1 and o2, and action being set
2750  !       to the fake action TheSame.  If it returns -1, they are found
2751  !       identical; if -2, different; and if >=0, then the usual method
2752  !       is used instead.
2753   
2754    if (o1.parse_name~=0 || o2.parse_name~=0)
2755    {   if (o1.parse_name ~= o2.parse_name) rfalse;
2756        parser_action=##TheSame; parser_one=o1; parser_two=o2;
2757        j=wn; i=RunRoutines(o1,parse_name); wn=j;
2758        if (i==-1) rtrue; if (i==-2) rfalse;
2759    }
2760   
2761  !  This is the default algorithm: do they have the same words in their
2762  !  "name" (i.e. property no. 1) properties.  (Note that the following allows
2763  !  for repeated words and words in different orders.)
2764   
2765    p1 = o1.&1; n1 = (o1.#1)/2;
2766    p2 = o2.&1; n2 = (o2.#1)/2;
2767   
2768  !  for (i=0:ii, " "; } new_line;
2769  !  for (i=0:ii, " "; } new_line;
2770   
2771    for (i=0:i<n1:i++)
2772    {   flag=0;
2773        for (j=0:j<n2:j++)
2774            if (p1-->i == p2-->j) flag=1;
2775        if (flag==0) rfalse;
2776    }
2777   
2778    for (j=0:j<n2:j++)
2779    {   flag=0;
2780        for (i=0:i<n1:i++)
2781            if (p1-->i == p2-->j) flag=1;
2782        if (flag==0) rfalse;
2783    }
2784   
2785  !  print "Which are identical!^";
2786    rtrue;
2787  ];


Last updated 27 February 2004. This web site has not been fully supported since April 2008. Information may be out of date. This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.