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

« back to all changes in this revision

Viewing changes to inform-6.31.1/include/money.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
!! money.h version 970331
 
2
!! Copyright 1997 Erik Hetzner
 
3
!! This file may be copied, modified and distributed freely, so long
 
4
!! as this notice remains. If it is modified, I ask that you change
 
5
!! the name somehow to indicate that changes have been made, and give
 
6
!! both you and me credit. You may include this library in any game so
 
7
!! long as you give me credit somewhere.
 
8
!! -- What is this? --
 
9
!! This is `money.h', an Inform header file that simulates
 
10
!! money. It is reasonably simple (I hope!) from your point of view
 
11
!! (that is, the point of view of you, the person including this
 
12
!! file!). Nevertheless, it needs some clarification:
 
13
!!
 
14
!! * You need a number of objects of class MetaMoneyClass. I'm not
 
15
!!   sure what exactly to call these -- in America, they would be
 
16
!!   dollars and cents. The must have value, sing_name, plur_name,
 
17
!!   sing and plur properties.
 
18
!! * All coins and bills to be used must also be defined, of class
 
19
!!   MoneyClass. They too must have value, sing_name, plur_name, sing
 
20
!!   and plur properties.
 
21
!! * You must define a number of constants:
 
22
!!
 
23
!!   1. MONEY_TOTAL: Total the money if it's in the player's possession
 
24
!!   2. MONEY_TOTAL_ON_GROUND: Total the money even if it's not in the
 
25
!!      player's possession.
 
26
!!   3. MONEY_SHOW: If the money is being totaled, show
 
27
!!      the individual coins and bills.
 
28
!!   4. MONEY_SHOW_ON_GROUND: Same as above, but applies to the
 
29
!!      ground (not in the player's possession.)
 
30
!!   5. MONEY_TALL_LIST: Show a tall list of the money if it's
 
31
!!      appropriate.
 
32
!!
 
33
!! * Read the example file, `greenbacks.inf'. Hopefully this file
 
34
!!   should make everything absolutely clear. If not, please write me!
 
35
!! * By default, there are 25 dynamically creatable pieces of
 
36
!!   money. If this is not enough, change the definition of MoneyClass.
 
37
!! -- BUGS! BUGS! BUGS! --
 
38
!! When you find a bug in this code, please write to me so that I can
 
39
!! fix the thing! Squash squash, you know? And I'm sure this code is
 
40
!! full of it. Too damned complex not to be. :)
 
41
!!
 
42
!! -- Future Enhancements --
 
43
!! * The ability to use commands like `drop four dollars' and have the
 
44
!!   computer what bills and coins to drop.
 
45
!! * It would be nice to have a change function, and a buy verb that
 
46
!!   would allow things to actually be done with the money you
 
47
!!   collect. :)
 
48
!!
 
49
!! -- About the author --
 
50
!! give self ego;
 
51
!! Erik Hetzner (that's me) was born in San Francisco on 24 August
 
52
!! 1978. He has lived all over Northern California, and has been
 
53
!! playing Interactive Fiction since grade 4. He got re-involved with
 
54
!! IF about two years ago. His past header files are `timepieces.h'
 
55
!! and `printtime.h'. He is currently working on at least two pieces
 
56
!! of IF -- and entry for the 1997 IF contest, and a longer work for
 
57
!! release at sometime. He will soon release the interactive Inform
 
58
!! Game List, a neat bit of coding that simulates a library. He is
 
59
!! also fiddling with the possibilities of using literate programming
 
60
!! tools with Inform. He is currently an undergraduate at UC Berkeley,
 
61
!! and finds that he spends far too much time fiddling with Inform.
 
62
!! give self ~ego;
 
63
!!
 
64
!! -- Contacting me --
 
65
!! Write to me at egh@uclink4.berkeley.edu. If you can't do this,
 
66
!! write me at: 2601 Warring Street Box 297; Berkeley, CA
 
67
!! 94720-2288. Failing this, call me at [510] 664-3565. Failing this,
 
68
!! write me at: 127 Brookmead Court; San Anselmo, CA 94960-1471. If
 
69
!! all else fails, call me at [415] 456-2759 (though I won't be
 
70
!! there!). If this isn't enough to get ahold of me, I don't know what
 
71
!! could possibly be. :)
 
72
 
 
73
Property value;
 
74
Property quantity;
 
75
 
 
76
Attribute money;
 
77
 
 
78
Global money_defs;
 
79
 
 
80
Array MetaMoney --> 4;
 
81
 
 
82
Constant MONEY_TOTAL_BIT = 1;
 
83
Constant MONEY_TOTAL_ON_GROUND_BIT = 2;
 
84
Constant MONEY_SHOW_BIT = 4;
 
85
Constant MONEY_SHOW_ON_GROUND_BIT = 8;
 
86
Constant MONEY_TALL_LIST_BIT = 16;
 
87
 
 
88
Class   MoneyClass(25)
 
89
 with   parse_name [ theWord quant x i;
 
90
            if (action == ##TheSame)
 
91
                return -1;
 
92
            else {
 
93
                quant = self.quantity;
 
94
                x = TryNumber (wn);
 
95
                if (x ~= -1000) {
 
96
                    quant = x;
 
97
                    x = true;
 
98
                    i++;
 
99
                    theWord = NextWord();
 
100
                }
 
101
                else
 
102
                    x = false;
 
103
                theWord = NextWord();
 
104
                if (theWord == 'money') {
 
105
                    self.number = 0;
 
106
                    parser_action = ##PluralFound;
 
107
                }
 
108
!               else if (WordInProperty (theWord, Values-->1, plur)) {
 
109
!                   
 
110
!                   ;
 
111
!               }    
 
112
                else if (WordInProperty (theWord, self, plur)) {
 
113
                    self.number = quant;
 
114
                }
 
115
                else if (WordInProperty (theWord, self, sing)) {
 
116
                    if (x == true)
 
117
                        self.number = quant;
 
118
                    else
 
119
                        self.number = 1;
 
120
                }
 
121
                else 
 
122
                    return 0;
 
123
                i++;
 
124
                return i;
 
125
            }
 
126
        ],
 
127
        list_together [;
 
128
            switch (inventory_stage) {
 
129
             1:
 
130
                if (((Descendant (self, player) == true) &&
 
131
                     ((money_defs & MONEY_TOTAL_BIT) ~= 0)) ||
 
132
                    ((parent (self) ~= player) &&
 
133
                     ((money_defs & MONEY_TOTAL_ON_GROUND_BIT) ~= 0)))
 
134
                {
 
135
                    print (TotalMoney) parent (self);
 
136
                } else
 
137
                    print "some money";
 
138
                if (((money_defs & MONEY_SHOW_BIT) ~= 0) &&
 
139
                    (Descendant (self, player) == true)) {
 
140
                    if ((money_defs & MONEY_TALL_LIST_BIT) ~= 0) {
 
141
                        if ((c_style & NEWLINE_BIT) ~= 0)
 
142
                                print ":^";
 
143
                            else
 
144
                                print " (";
 
145
                        rfalse;
 
146
                    }
 
147
                    else {
 
148
                        if ((c_style & NEWLINE_BIT) ~= 0) {
 
149
                            print " (";
 
150
                            c_style = ENGLISH_BIT + FULLINV_BIT +
 
151
                                RECURSE_BIT;
 
152
                        }
 
153
                        else
 
154
                            print " (";
 
155
                        rfalse;
 
156
                    }
 
157
                }
 
158
                if (((money_defs & MONEY_SHOW_ON_GROUND_BIT) ~= 0) &&
 
159
                    (Descendant (self, player) == false)) {
 
160
                    print " (";
 
161
                    c_style = ENGLISH_BIT + FULLINV_BIT +
 
162
                        RECURSE_BIT;
 
163
                    rfalse;
 
164
                }
 
165
                if (Descendant (self, player) == true)
 
166
                    print "^";
 
167
                rtrue;
 
168
             2:
 
169
                if (((c_style & NEWLINE_BIT) == 0) &&
 
170
                    ((Descendant (self, player) == true) &&
 
171
                     ((money_defs & MONEY_TOTAL_BIT) ~= 0)) ||
 
172
                    ((Descendant (self, player) == false) &&
 
173
                     ((money_defs & MONEY_TOTAL_ON_GROUND_BIT) ~= 0)))
 
174
                    print ")";
 
175
            }
 
176
        ],
 
177
        article [;
 
178
            print (MonQuant) self;
 
179
        ],
 
180
        short_name [;
 
181
            print (MonSingOrPlur) self;
 
182
            rtrue;
 
183
        ],
 
184
        create [;
 
185
            StartDaemon (self);
 
186
        ],
 
187
        destroy [;
 
188
            remove self;
 
189
            StopDaemon (self);
 
190
        ],  
 
191
        daemon [;
 
192
            CombineMoney (self);
 
193
            self.number = 0;
 
194
        ],
 
195
        before [ x;
 
196
            if (self.number == 0)
 
197
                self.number = self.quantity;
 
198
            else if (self.number > self.quantity) {
 
199
                print "(There aren't that many ", (MonPlur) self,
 
200
                    ", but I'll use as many as I can.)^";
 
201
                self.number = self.quantity;
 
202
            }
 
203
            else if (self.quantity ~= self.number) {
 
204
                if (SplitMoney (self, self.number) == false)
 
205
                    rtrue;
 
206
            }
 
207
         Take:
 
208
            objectloop (x in player)
 
209
                if (x ofclass MoneyClass)
 
210
                    if (x.value == self.value) {
 
211
                        x.quantity = x.quantity + self.quantity;
 
212
                        self.destroy ();
 
213
                        "Taken.";
 
214
                    }
 
215
            move self to player;
 
216
            "Taken.";
 
217
         Drop:
 
218
            if (noun notin player)
 
219
                "You're not carrying any ", (MonPlur) noun, ".";
 
220
            objectloop (x in Location)
 
221
                if (x ofclass MoneyClass)
 
222
                    if (x.value == self.value) {
 
223
                        x.quantity = x.quantity + self.quantity;
 
224
                        self.destroy ();
 
225
                        "Dropped.";
 
226
                    }
 
227
            move self to Location;
 
228
            "Dropped.";
 
229
        ],
 
230
        sing_name,
 
231
        plur_name,
 
232
        sing,
 
233
        plur,
 
234
        value,
 
235
        quantity,
 
236
        number,
 
237
 has    money;
 
238
 
 
239
Class   MetaMoneyClass
 
240
 with   sing_name,
 
241
        plur_name,
 
242
        sing,
 
243
        plur,
 
244
        value;
 
245
 
 
246
[ RSortTableByProp table prop i temp;
 
247
    for (i = 1: (i - 2) ~= table-->0: i++) {
 
248
        if ((table-->i).prop < (table-->(i+1)).prop) {
 
249
            temp = table-->i;
 
250
            table-->i = table-->(i+1);
 
251
            table-->(i+1) = temp;
 
252
            i = 1;
 
253
        }
 
254
    }
 
255
];
 
256
 
 
257
[ CombineMoney the_object x;
 
258
    if (the_object.quantity == 0) {
 
259
        remove the_object;
 
260
        StopDaemon (the_object);
 
261
    }
 
262
    for (x = child (parent (the_object)): x ~= nothing :
 
263
         x = sibling (x)) {
 
264
        if ((x ofclass MoneyClass) && (x ~= the_object) &&
 
265
            (x.value == the_object.value)) {
 
266
            x.quantity = (the_object.quantity + x.quantity);
 
267
            the_object.destroy ();
 
268
        }
 
269
    }
 
270
];
 
271
 
 
272
[ MonQuant theObject;
 
273
    if (theObject.quantity == 1)
 
274
        print "a";
 
275
    else
 
276
        print (number) theObject.quantity;
 
277
];
 
278
 
 
279
[ MonPlur theObject;
 
280
    print (string) theObject.plur_name;
 
281
];
 
282
 
 
283
[ MonSing theObject;
 
284
    print (string) theObject.sing_name;
 
285
];
 
286
 
 
287
[ MonSingOrPlur theObject;
 
288
    if (theObject.quantity == 1) 
 
289
        print (MonSing) theObject;
 
290
    else if (theObject.quantity > 1)
 
291
        print (MonPlur) theObject;
 
292
];         
 
293
 
 
294
![ MonIsOrAre theObject;
 
295
!    if (theObject.quantity > 1)
 
296
!       print "are";
 
297
!    else
 
298
!       print "is";
 
299
!];    
 
300
 
 
301
[ TotalMoney parentObj total x y z object;
 
302
    objectloop (x in parentObj)
 
303
        if (x ofclass MoneyClass)
 
304
            total = total + (x.value * x.quantity);
 
305
    y = total;
 
306
    for (x = 1 : x <= MetaMoney-->0 : x++) {
 
307
        object = (MetaMoney-->x);       
 
308
        z = (y/object.value);
 
309
        if (z == 0)
 
310
            ;
 
311
        else {
 
312
            if (z > 1)
 
313
                print (number) z, " ", (MonPlur) object;
 
314
            else
 
315
                print (number) z, " ", (MonSing) object;
 
316
            y = y%(object.value);
 
317
            if ((x) ~= (MetaMoney-->0)) {
 
318
                if ((x+1) == (MetaMoney-->0))
 
319
                    print " and ";
 
320
                else
 
321
                    print ", ";
 
322
            }
 
323
        }
 
324
    }
 
325
    return total;
 
326
];
 
327
 
 
328
![ ListMoney parentObj x y z;
 
329
!    y = 0;
 
330
!    z = 0;
 
331
!    objectloop (x in parentObj)
 
332
!       if (x ofclass MoneyClass)
 
333
!           y++;
 
334
!    for (x = child (parentObj): x ~= nothing: x = sibling (x)) {
 
335
!       if (x ofclass MoneyClass) {
 
336
!           z++;
 
337
!           print (MonQuant) x, " ", (MonSingOrPlur) x;
 
338
!           if (z ~= y) {
 
339
!               if (z+1 == y)
 
340
!                   print " and ";
 
341
!               else
 
342
!                   print ", ";
 
343
!           }
 
344
!       }       
 
345
!    }
 
346
!];    
 
347
 
 
348
[ SplitMoney origObj quant x;
 
349
    objectloop (x ofclass MoneyClass) {
 
350
        if (parent (x) == nothing) {
 
351
            move x to parent (origObj);
 
352
            MoneyClass.copy (x, origObj);
 
353
            x.quantity = origObj.quantity - quant;
 
354
            origObj.quantity = quant;
 
355
            x.create ();
 
356
            if (x.quantity < 1)
 
357
                remove (x);
 
358
            rtrue;
 
359
        }
 
360
    }
 
361
    if (MoneyClass.remaining () > 0) {  
 
362
        x = MoneyClass.create ();
 
363
        MoneyClass.copy (x, origObj);
 
364
        x.quantity = (origObj.quantity - quant);
 
365
        origObj.quantity = quant;
 
366
        move x to parent (origObj);
 
367
        if (x.quantity < 1)
 
368
            remove (x);
 
369
        rtrue;
 
370
    }
 
371
    print "^money.h: A very bad thing has happened. There are not \
 
372
        enough separate money objects. Consolidate your money or \
 
373
        report this error to the game programmer.^";
 
374
    rfalse;
 
375
];
 
376
 
 
377
[ Descendant childObj parentObj tempObj;
 
378
    for (tempObj = parent (childObj):tempObj ~= nothing:
 
379
         tempObj = parent (tempObj)) {
 
380
        if (tempObj == parentObj)
 
381
            rtrue;
 
382
    }
 
383
    rfalse;
 
384
];
 
385
 
 
386
[ InitMoney i x;
 
387
    money_defs = 0;
 
388
    #ifdef MONEY_TOTAL;
 
389
    money_defs = money_defs + MONEY_TOTAL_BIT;
 
390
    #endif;
 
391
    #ifdef MONEY_TOTAL_ON_GROUND;
 
392
    money_defs = money_defs + MONEY_TOTAL_ON_GROUND_BIT;
 
393
    #endif;
 
394
    #ifdef MONEY_TALL_LIST;
 
395
    money_defs = money_defs + MONEY_TALL_LIST_BIT;
 
396
    #endif;
 
397
    #ifdef MONEY_SHOW;
 
398
    money_defs = money_defs + MONEY_SHOW_BIT;
 
399
    #endif;
 
400
    #ifdef MONEY_SHOW_ON_GROUND;
 
401
    money_defs = money_defs + MONEY_SHOW_ON_GROUND_BIT;
 
402
    #endif;
 
403
    objectloop (x ofclass MetaMoneyClass) {
 
404
        i++;
 
405
        MetaMoney-->0 = i;
 
406
        MetaMoney-->i = x;
 
407
    }
 
408
    RSortTableByProp (MetaMoney, value);
 
409
    objectloop (x ofclass MoneyClass)
 
410
    {
 
411
        if (x.quantity > 0)
 
412
            x.create ();
 
413
        else
 
414
            x.destroy ();
 
415
    }      
 
416
];
 
417
 
 
418