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.
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:
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:
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
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. :)
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
49
!! -- About the author --
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.
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. :)
80
Array MetaMoney --> 4;
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;
89
with parse_name [ theWord quant x i;
90
if (action == ##TheSame)
93
quant = self.quantity;
103
theWord = NextWord();
104
if (theWord == 'money') {
106
parser_action = ##PluralFound;
108
! else if (WordInProperty (theWord, Values-->1, plur)) {
112
else if (WordInProperty (theWord, self, plur)) {
115
else if (WordInProperty (theWord, self, sing)) {
128
switch (inventory_stage) {
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)))
135
print (TotalMoney) parent (self);
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)
148
if ((c_style & NEWLINE_BIT) ~= 0) {
150
c_style = ENGLISH_BIT + FULLINV_BIT +
158
if (((money_defs & MONEY_SHOW_ON_GROUND_BIT) ~= 0) &&
159
(Descendant (self, player) == false)) {
161
c_style = ENGLISH_BIT + FULLINV_BIT +
165
if (Descendant (self, player) == true)
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)))
178
print (MonQuant) self;
181
print (MonSingOrPlur) self;
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;
203
else if (self.quantity ~= self.number) {
204
if (SplitMoney (self, self.number) == false)
208
objectloop (x in player)
209
if (x ofclass MoneyClass)
210
if (x.value == self.value) {
211
x.quantity = x.quantity + self.quantity;
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;
227
move self to Location;
246
[ RSortTableByProp table prop i temp;
247
for (i = 1: (i - 2) ~= table-->0: i++) {
248
if ((table-->i).prop < (table-->(i+1)).prop) {
250
table-->i = table-->(i+1);
251
table-->(i+1) = temp;
257
[ CombineMoney the_object x;
258
if (the_object.quantity == 0) {
260
StopDaemon (the_object);
262
for (x = child (parent (the_object)): x ~= nothing :
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 ();
272
[ MonQuant theObject;
273
if (theObject.quantity == 1)
276
print (number) theObject.quantity;
280
print (string) theObject.plur_name;
284
print (string) theObject.sing_name;
287
[ MonSingOrPlur theObject;
288
if (theObject.quantity == 1)
289
print (MonSing) theObject;
290
else if (theObject.quantity > 1)
291
print (MonPlur) theObject;
294
![ MonIsOrAre theObject;
295
! if (theObject.quantity > 1)
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);
306
for (x = 1 : x <= MetaMoney-->0 : x++) {
307
object = (MetaMoney-->x);
308
z = (y/object.value);
313
print (number) z, " ", (MonPlur) object;
315
print (number) z, " ", (MonSing) object;
316
y = y%(object.value);
317
if ((x) ~= (MetaMoney-->0)) {
318
if ((x+1) == (MetaMoney-->0))
328
![ ListMoney parentObj x y z;
331
! objectloop (x in parentObj)
332
! if (x ofclass MoneyClass)
334
! for (x = child (parentObj): x ~= nothing: x = sibling (x)) {
335
! if (x ofclass MoneyClass) {
337
! print (MonQuant) x, " ", (MonSingOrPlur) x;
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;
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);
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.^";
377
[ Descendant childObj parentObj tempObj;
378
for (tempObj = parent (childObj):tempObj ~= nothing:
379
tempObj = parent (tempObj)) {
380
if (tempObj == parentObj)
389
money_defs = money_defs + MONEY_TOTAL_BIT;
391
#ifdef MONEY_TOTAL_ON_GROUND;
392
money_defs = money_defs + MONEY_TOTAL_ON_GROUND_BIT;
394
#ifdef MONEY_TALL_LIST;
395
money_defs = money_defs + MONEY_TALL_LIST_BIT;
398
money_defs = money_defs + MONEY_SHOW_BIT;
400
#ifdef MONEY_SHOW_ON_GROUND;
401
money_defs = money_defs + MONEY_SHOW_ON_GROUND_BIT;
403
objectloop (x ofclass MetaMoneyClass) {
408
RSortTableByProp (MetaMoney, value);
409
objectloop (x ofclass MoneyClass)