Inform - Resources - Examples

Back to List

Inventory
Complete

Backward
At End

Plain
Coloured
Gaudy

This code
in plain text

Browsing Museum.inf

Grammar (lines 1925-2169)

1925  Include "Grammar";
1926   
1927  ! --------------------------------------------------------------------------
1928   
1929  [ FPXSub;
1930      "You typed the floating point number ", noun/100, ".",
1931      (noun%100)/10, noun%10, " (rounded off to 2 decimal places.)";
1932  ];
1933   
1934  [ DigitNumber n type x;
1935    x = NextWordStopped(); if (x==-1) return -1; wn--;
1936    if (type==0)
1937    {   x = WordAddress(wn);
1938        if (x->n>='0' && x->n<='9') return (x->n) - '0';
1939        return -1;
1940    }
1941    if (x=='nought' or 'oh') { wn++; return 0; }
1942    x = TryNumber(wn++); if (x==-1000 || x>=10) x=-1; return x;
1943  ];
1944  [ FloatingPoint a x b w d1 d2 d3 type;
1945    a = TryNumber(wn++);
1946    if (a==-1000) return -1;
1947    w = NextWordStopped(wn); if (w==-1) return a*100;
1948    x = NextWordStopped(wn); if (x==-1) return -1; wn--;
1949    if (w=='point') type=1;
1950    else
1951    {   if (WordAddress(wn-1)->0~='.' || WordLength(wn-1)~=1)
1952            return -1;
1953    }
1954    d1 = DigitNumber(0,type);
1955    if (d1==-1) return -1;
1956    d2 = DigitNumber(1,type); d3 = DigitNumber(2,type);
1957    b=d1*10; if (d2>=0) b=b+d2; else d3=0;
1958    if (type==1)
1959    {   x=1; while (DigitNumber(x,type)>=0) x++; wn--;
1960    }
1961    else wn++;
1962    parsed_number = a*100 + b;
1963    if (d3>=5) parsed_number++;
1964    return 1;
1965  ];
1966   
1967  Verb "fp" * FloatingPoint -> FPX;
1968   
1969  ! --------------------------------------------------------------------------
1970   
1971  Constant MAX_PHONE_LENGTH 30;
1972  Array dialled_number string MAX_PHONE_LENGTH;
1973  [ PhoneNumber f a l ch pp i;
1974    pp=1; if (NextWordStopped()==-1) return 0;
1975    do
1976    {   a=WordAddress(wn-1); l=WordLength(wn-1);
1977        for (i=0:i<l:i++)
1978        {   ch=a->i;
1979            if (ch<'0' || ch>'9')
1980            {   if (ch~='-') { f=1; if (i~=0) return -1; } }
1981            else
1982            {   if (pp<MAX_PHONE_LENGTH)
1983                    dialled_number->(pp++)=ch-'0';
1984            }
1985        }
1986    } until (f==1 || NextWordStopped()==-1);
1987    if (pp==1) return -1;
1988    dialled_number->0 = pp-1;
1989    return 0;
1990  ];
1991   
1992  [ DialPhoneSub i;
1993    print "You dialled <";
1994    for (i=1:i<=dialled_number->0:i++) print dialled_number->i;
1995    ">";
1996  ];
1997  Verb "dial"  * PhoneNumber -> DialPhone;
1998   
1999  ! --------------------------------------------------------------------------
2000   
2001  Global assumed_key;
2002  [ DefaultLockSub;
2003    print "(with ", (the) assumed_key, ")^"; <<Lock noun assumed_key>>;
2004  ];
2005  [ DefaultUnlockSub;
2006    print "(with ", (the) assumed_key, ")^"; <<Unlock noun assumed_key>>;
2007  ];
2008   
2009  [ DefaultKeyTest i count;
2010    if (noun hasnt lockable) rfalse;
2011   
2012    objectloop (i in player && i ofclass Key)
2013    {   count++; assumed_key = i; }
2014   
2015    if (count==1) rtrue; rfalse;
2016  ];
2017   
2018  Extend "lock" first * noun = DefaultKeyTest -> DefaultLock;
2019  Extend "unlock" first * noun = DefaultKeyTest -> DefaultUnlock;
2020   
2021  ! --------------------------------------------------------------------------
2022   
2023  Constant TWELVE_HOURS 720;
2024  [ NumericTime hr mn word x;
2025    if (hr>=24) return -1;
2026    if (mn>=60) return -1;
2027    x=hr*60+mn; if (hr>=13) return x;
2028    x=x%TWELVE_HOURS; if (word=='pm') x=x+TWELVE_HOURS;
2029    if (word~='am' or 'pm' && hr==12) x=x+TWELVE_HOURS;
2030    return x;
2031  ];
2032  [ MyTryNumber wordnum i j;
2033    i=wn; wn=wordnum; j=NextWordStopped(); wn=i;
2034    switch(j)
2035    {   'twenty-five': return 25;
2036        'thirty': return 30;
2037        default: return TryNumber(wordnum);
2038    }
2039  ];
2040  [ TimeOfDay i j k x flag loop ch hr mn;
2041    i=NextWord();
2042    if (i=='midnight') { parsed_number=0; return 1; }
2043    if (i=='midday' or 'noon') { parsed_number=TWELVE_HOURS; return 1; }
2044    !   Next try the format 12:02
2045    j=WordAddress(wn-1); k=WordLength(wn-1);
2046    flag=0;
2047    for (loop=0:loop<k:loop++)
2048    {   ch=j->loop;
2049        if (ch==':' && flag==0 && loop~=0 && loop~=k-1) flag=1;
2050        else { if (ch<'0' || ch>'9') flag=-1; }
2051    }
2052    if (k<3 || k>5) flag=0;
2053    if (flag==1)
2054    {   for (loop=0:j->loop~=':':loop++, hr=hr*10)
2055            hr=hr+j->loop-'0';
2056        hr=hr/10;
2057        for (loop++:loop<k:loop++, mn=mn*10)
2058            mn=mn+j->loop-'0';
2059        mn=mn/10;
2060        j=NextWordStopped();
2061        parsed_number=NumericTime(hr, mn, j);
2062        if (parsed_number<0) return -1;
2063        if (j~='pm' or 'am') wn--;
2064        return 1;
2065    }
2066    !   Next the format "half past 12"
2067    j=-1; if (i=='half') j=30; if (i=='quarter') j=15;
2068    if (j<0) j=MyTryNumber(wn-1); if (j<0) return -1;
2069    if (j>=60) return -1;
2070    k=NextWordStopped();
2071    if ((k=='o^clock' or 'am' or 'pm')||(k==-1))
2072    {   hr=j; if (hr>12) return -1; jump TimeFound; }
2073    if (k=='to' or 'past')
2074    {   mn=j; hr=MyTryNumber(wn);
2075        if (hr<=0)
2076        {   x=NextWordStopped();
2077            if (x=='noon' or 'midday') hr=12;
2078            if (x=='midnight') hr=0;
2079            if (hr<0) return -1;
2080        }
2081        if (hr>=13) return -1;
2082        if (k=='to') { mn=60-mn; hr=hr-1; if (hr==-1) hr=23; }
2083        wn++; k=NextWordStopped();
2084        jump TimeFound;
2085    }
2086    hr=j; mn=MyTryNumber(--wn);
2087    if (mn<0 || mn>=60) return -1;
2088    wn++; k=NextWordStopped();
2089   .TimeFound;
2090    parsed_number = NumericTime(hr, mn, k);
2091    if (parsed_number<0) return -1;
2092    if (k~='pm' or 'am' or 'o^clock') wn--;
2093    return 1;
2094  ];
2095   
2096  [ SetTheTimeSub;
2097    SetTime(noun,1);
2098    "The time is set to ", (PrintTime) noun, ".";
2099  ];
2100  Verb "time"  * TimeOfDay -> SetTheTime;
2101   
2102  ! --------------------------------------------------------------------------
2103   
2104  Global third;
2105  [ ThreefoldSub; "You do something involving ", (the) noun, ", ",
2106        (the) second, " and ", (the) third, ".";
2107  ];
2108  [ GhostObject x;
2109    x=NounDomain(player,location,0);
2110    if (x==REPARSE_CODE) return x;
2111    if (x==0 or 1) return -1;
2112    third = x;
2113    return 0;
2114  ];
2115  Verb "threefold" * noun noun GhostObject -> Threefold;
2116                 
2117  ! --------------------------------------------------------------------------
2118   
2119  [ MegaExam obj; print (a) obj, ": "; <Examine obj>; ];
2120  [ MegaLookSub; <Look>; LoopOverScope(MegaExam); ];
2121  Verb meta "megalook" *                           -> MegaLook;
2122   
2123  ! --------------------------------------------------------------------------
2124   
2125  [ ClapSub; "You clap."; ];
2126  Verb "clap"   * -> Clap;
2127   
2128  ! --------------------------------------------------------------------------
2129   
2130  Verb "magnify" * noun                          -> Magnify;
2131   
2132  ! --------------------------------------------------------------------------
2133   
2134  Verb "alarm," * "on"      -> SwitchOn
2135                * "off"     -> SwitchOff
2136                * TimeOfDay -> SetTo
2137                * ConTopic  -> Inv;
2138   
2139  Verb "tc,"    * noun      -> Examine
2140                * ConTopic  -> Inv;
2141   
2142  [ Crew i;
2143    switch(scope_stage)
2144    {  1: rfalse;
2145       2: objectloop (i has crewmember) PlaceInScope(i); rtrue;
2146    }
2147  ];
2148   
2149  Verb "stc,"   * "where" "is" scope=Crew        -> Examine
2150                * "locate" scope=Crew            -> Examine;
2151   
2152  Verb "rc,"    * held      -> Give
2153                * ConTopic  -> Inv;
2154   
2155  [ Planet;
2156    switch(NextWord())
2157    {   'centauro', 'earth': return 1;
2158        default: return -1;
2159    }
2160  ];
2161   
2162  Verb "zen,"   * "scan" number "orbital"        -> Show
2163                * "set" "course" "for" Planet    -> Go
2164                * "speed" "standard" "by" number -> SetTo
2165                * "raise" held                   -> Take
2166                * "clear" held "for" "firing"    -> Drop;
2167   
2168  ! ----------------------------------------------------------------------------
2169   


Last updated 23 June 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.