~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to include/calyx_adjectives.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
! ---------------------------------------------------------------------------
2
 
! calyx_adjectives - This Inform library extension is heavily based on Andrew
3
 
!       Clover's adname.h (which in turn is based on an example in the Inform
4
 
!       Designers Manual).
5
 
!       Differences: * The adname property is additive.
6
 
!                    * The main Class is called Ad_Item instead of adnc.
7
 
!                    * Objects can be referred-to by an adname alone. The
8
 
!                      price to pay is that you have to take care of the
9
 
!                      actual difference yourself (see example below).
10
 
!       Release 1.
11
 
!
12
 
!       Include this library before you define your objects.
13
 
!       Written in 1997 by Miron Schmidt / Calyx. Placed in the
14
 
!       Public Domain. Actually, I've only given it a new name at all because
15
 
!       it is incompatible to Andrew's library.
16
 
!
17
 
!       Example:
18
 
!       First, define an object like this:
19
 
!               Ad_Item cigarette_lighter "cigarette lighter"
20
 
!                 with name 'lighter',
21
 
!                      adname 'cigarette',
22
 
!                      ...
23
 
!                 has ...;
24
 
!       Then, in ChooseObjects(), put in the following code:
25
 
!               [ ChooseObjects obj code prio;
26
 
!                       if (code <2) { Your code }
27
 
!                       prio=2;
28
 
!                       ...
29
 
!                       if (obj has adj_chosen)  return prio;
30
 
!                       return prio+10;
31
 
!               ];
32
 
!       You can define your own ChooseObjects() priorities, but an object
33
 
!       that was referred-to by its (noun) name should always have a higher
34
 
!       priority than an object that was referred-to by an adname only.
35
 
!
36
 
!       adj_chosen is an attribute that is set if the player referred to an
37
 
!       object by adnames only (e.g. 'cigarette' in the example).
38
 
!       Thus, a cigarette would be automatically chosen if it were in the
39
 
!       same room as the lighter, but in other circumstances, 'cigarette'
40
 
!       could also refer to the lighter.
41
 
! ---------------------------------------------------------------------------
42
 
 
43
 
System_file;
44
 
 
45
 
Property additive adname;
46
 
Attribute adj_chosen;                   ! This is set if the object was
47
 
                                        ! chosen because of an adname.
48
 
                                        ! You may use this knowledge in a
49
 
                                        ! ChooseObjects routine.
50
 
 
51
 
Class Ad_Item
52
 
  with
53
 
    adname 'the',                       ! If adname is 0, program crashes!
54
 
    parse_name [;
55
 
      return AdnameParser(self);        ! Calling another routine like this
56
 
                                        ! avoids excessive code duplication,
57
 
                                        ! and allows you to extend an
58
 
                                        ! object's parse_name routine whilst
59
 
                                        ! still calling the adname parser.
60
 
    ]
61
 
  has adj_chosen;
62
 
 
63
 
[ AdnameParser adobj w n i j a b succ fail;
64
 
  if (parser_action==##TheSame) {
65
 
    w=parser_one.&adname;
66
 
    n=(parser_one.#adname)/2;
67
 
    i=parser_two.&adname;
68
 
    j=(parser_two.#adname)/2;
69
 
    for (a=0:a<n:a++) {
70
 
      fail=1;
71
 
      for (b=0:b<j:b++) {
72
 
        if ((w-->a)==(i-->b))
73
 
          fail=0;
74
 
      }
75
 
      if (fail==1)  return -2;
76
 
    }
77
 
    for (a=0:a<j:a++) {
78
 
      fail=1;
79
 
      for (b=0:b<n:b++) {
80
 
        if ((w-->b)==(i-->a))
81
 
          fail= 0;
82
 
      }
83
 
      if (fail==1)  return -2;
84
 
    }
85
 
    return 0;   ! This bit adapted from the parser - check all words in
86
 
                ! adname of parser_one to see if they occur in adname of
87
 
                ! parser_two, then vice-versa. If either case is false, we
88
 
                ! say the objects are not the same (the player may type a
89
 
                ! word that distiguishes then); if both are true, we give the
90
 
                ! parser a crack at seeing if they're different (by looking
91
 
                ! at the name property).
92
 
  }
93
 
  else {
94
 
    n=0;
95
 
    succ=0;
96
 
    fail=0;
97
 
    while (fail==0) {
98
 
      fail=1;
99
 
      w=NextWord();
100
 
      for (i=0:i<(adobj.#adname)/2:i++) {
101
 
        if (w==adobj.&adname-->i) {
102
 
          fail=0;
103
 
          succ=1;
104
 
          give adobj adj_chosen;
105
 
        }
106
 
      }
107
 
      for (i=0:i<(adobj.#name)/2:i++) {
108
 
        if (w==adobj.&name-->i) {
109
 
          fail=0;
110
 
          succ=1;
111
 
          give adobj ~adj_chosen;
112
 
        }
113
 
      }
114
 
      n++;
115
 
    }
116
 
    if (succ==1)  return n-1;
117
 
    return 0;
118
 
                ! This is the bit of code executed normally (when the parser
119
 
                ! isn't trying to resolve identical objects). We just check
120
 
                ! that every word typed is in the adname or name property,
121
 
                ! and say that the phrase matches the object if any words are
122
 
                ! in the name.
123
 
  }
124
 
];