-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.c
200 lines (182 loc) · 4.97 KB
/
item.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* ScottCom -- Compiles adventures into the Scott Adams format.
* Copyright (C) 1985-1996 Bjorn Gustavsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: item.c,v 1.1 1996/01/12 08:01:16 bjorn Exp $
*
*/
#include "scottcom.h"
#include "adams.h"
static int CurrentItem = 0;
static char *NameTable[256]; /* Name of all items. */
static char OwnerTable[256]; /* Owner of all items. */
static char LinkTable[256]; /* Noun link for all items. */
static int NoTreasures = 0; /* Count of treasures in game. */
/*----------------------------------------------------------------------
*
* GetNextItem --
*
* This function retrieves the number of the next
* free item number. It will generate an error
* message if the number would be greater than 255.
* This function will never return 9, because that item
* number is reserved for the light source.
*
* Results:
* The number of the next free item.
*
*----------------------------------------------------------------------
*/
int
GetNextItem(void)
{
if (CurrentItem == LIGHT_SOURCE)
CurrentItem++;
if (CurrentItem == 256) {
CurrentItem--;
error("too many items defined");
}
return CurrentItem++;
}
/*----------------------------------------------------------------------
*
* SetItem --
*
* This procedure sets the name, owner, and associated noun
* for an item. The item number must have been obtained from
* the GetNextItem() function, or be the constant LIGHT_SOURCE.
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
SetItem(
int item, /* Number of item. */
char* name, /* Description of item. */
int owner, /* Owner of item. */
int link) /* Noun by which item can be named, */
/* or 0 if no such noun. */
{
if (item == LIGHT_SOURCE && NameTable[item] != 0) {
error("attempt to define more than one light source");
return;
}
ASSERT(NameTable[item] == 0); /* Impossible to assign more than once. */
NameTable[item] = name;
if (name[0] == '*')
NoTreasures++;
OwnerTable[item] = owner;
LinkTable[item] = link;
}
/*----------------------------------------------------------------------
*
* FixLightSource --
*
* This procedure handles the issues of the light source
* (item 9):
*
* 1. If the game has no light source, item 9 will get
* a dummy name (to avoid having a null pointer).
*
* 2. If there are less than nine items in a game, make
* sure that we define dummy items before item 9.
*
* 3. If the game defines a light source, check that the
* the 'light_time' parameter was given.
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
FixLightSource(void)
{
while (CurrentItem < LIGHT_SOURCE) {
NameTable[CurrentItem++] = strsave(".");
}
if (CurrentItem <= LIGHT_SOURCE) {
CurrentItem++;
}
if (NameTable[9] == 0) {
NameTable[9] = strsave("."); /* Give the light source a dummy name. */
/* The strsave() is necessary to assure */
/* that the string can be written to */
/* (Transform() will be used). */
} else if (info.light_time == 0) {
error("there is a light source, but 'light_time' is not set");
}
}
void ti99_DumpItems(void) /* dump item tables */
{
int i;
int Owner1, Owner2, Link, Name;
if (verbose)
printf("Number of items = %d\n", CurrentItem);
if (CurrentItem == 0) {
error("no items defined");
return;
}
/*
* Output the first owner table
*/
Org(Owner1 = Here());
for (i = 0; i < CurrentItem; i++)
{
if(verbose)
{
int k;
Room *r = room->next;
k = OwnerTable[i];
while(k > 0)
{
r=r->next;
k -= 1;
}
printf("\t%3i) %-20s => %s, Links to %i (%s)\n", i, NameTable[i], r->name, LinkTable[i], NounNames[(int)LinkTable[i]]->name);
}
OutByte(OwnerTable[i]);
}
/*
* Output the second owner table
*/
Owner2 = OutAddress();
for (i = 0; i < CurrentItem; i++)
OutByte(OwnerTable[i]);
Link = OutAddress();
/*
* Output item to noun link table
*/
for (i = 0; i < CurrentItem; i++)
OutByte(LinkTable[i]);
/*
* Output item description table
*/
Name = PutDescTable(NameTable, CurrentItem);
SetHere(OutAddress());
Org(OBJS);
OutByte(CurrentItem-1);
Org(OBJTABLE);
OutWord(Owner1);
OutWord(Owner2);
OutWord(Link);
OutWord(Name);
Org(NOTREA);
OutByte(NoTreasures);
}