-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathularn_game.c
331 lines (277 loc) · 9.42 KB
/
ularn_game.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/* =============================================================================
* PROGRAM: vlarn
* FILENAME: vlarn_game.h
*
* DESCRIPTION:
* Game data used by VLarn.
* This Contains:
* . The names of data files used by vlarn
* . The player's name
* . Current game options
*
* =============================================================================
* EXPORTED VARIABLES
*
* do_fork : True if fork on save (now unsupported)
* boldon : True if objects are to be dislayed in bold (tty only)
* mail : True if mail bills when game is won
* ckpflag : True if checkpoint files are to be used.
* nobeep : True if beep is off.
* libdir : VLarn library path
* savedir : Directroy for save games
* savefilename : Filename for saving the game
* scorefile : Filename for the scores
* helpfile : Filename for vlarn help
* larnlevels : Filename for pregenerated levels
* fortfile : Filename for fortunes
* optsfile : VLarn options file
* ckpfile : Checkpoint file name
* diagfile : Diagnostic dump file name
* userid : User Id of the player
* password : Wizard password
* loginname : The login name of the player
* logname : The name to appear on the score board
* nowelcome : True if no welcome message is to be displayed
* nomove : True if player action resulted in no move.
* dropflag : True if the player just dropped the item
* restoreflag : True if the game is to be restored from a file
* diroffx : Direction offsets for x coordinate
* diroffy : Direction offsets for y coordinate
* ReverseDir : Lookup for the index of the reverse direction
* dirname : The name of each direction.
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* newgame : Funtion to initialise a new game.
* sethard : Function to set the game difficulty
* read_options : Function to read the vlarn options file
*
* =============================================================================
*/
#include <time.h>
#include "header.h"
#include "monster.h"
#include "player.h"
#include "ularn_game.h"
/* =============================================================================
* Exported variables
*/
/*
* Game options
*/
char do_fork = 0; /* 1=fork on save, 0=save from main process. NOT SUPPORTED */
char boldon = 1; /* 1=bold objects, 0=inverse objects */
char mail = 1; /* 1=mail letters after win game */
char ckpflag = 1; /* 1 if want checkpointing of game, 0 otherwise */
char nobeep = 0; /* true if program is not to beep*/
char libdir[MAXPATHLEN] = LIBDIR;
char savedir[MAXPATHLEN];
/* the game save filename */
char savefilename[MAXPATHLEN + 255];
/* the temporary save filename */
char tempfilename[MAXPATHLEN + 32];
/* the score file */
char scorefile[MAXPATHLEN + 16];
/* the help text file */
char helpfile[MAXPATHLEN + 16];
/* the maze data file */
char larnlevels[MAXPATHLEN + 16];
/* the fortune data file */
char fortfile[MAXPATHLEN + 16];
/* the options file filename */
char optsfile[MAXPATHLEN + 16] = "vlarn.opt";
/* the checkpoint file filename */
char ckpfile[MAXPATHLEN + 16] = "vlarn.ckp";
/* the diagnostic filename */
char diagfile[] = "diagfile.txt";
/* the wizard's password */
char *password = "rodney";
int userid; /* the players login user id number */
char loginname[USERNAME_LENGTH + 1]; /* players login name */
char logname[LOGNAMESIZE + 1]; /* players name storage for scoring */
char nowelcome = 0; /* if nowelcome, don't display welcome message */
char nomove = 0; /* if nomove no count next iteration as move */
char dropflag = 0; /* if 1 then don't lookforobject() next round */
char restorflag = 0; /* 1 means restore has been done */
char enhance_interface = 0; /* 1 means use the enhanced command interface */
char diroffx[] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
char diroffy[] = {0, 1, 0, -1, 0, -1, -1, 1, 1};
int ReverseDir[] = {0, 3, 4, 1, 2, 8, 7, 6, 5};
char *dirname[] = {"None", "South", "East", "North", "West",
"Northeast", "Northwest", "Southeast", "Southwest"};
/* =============================================================================
* Local variables
*/
#define LINE_LEN 256
typedef enum {
OPTION_NULL,
OPTION_NAME,
OPTION_CLASS,
OPTION_GENDER,
OPTION_NAP,
OPTION_NONAP,
OPTION_WELCOME,
OPTION_NOWELCOME,
OPTION_ENHANCE_INT,
OPTION_NOENHANCE_INT,
OPTION_BEEP,
OPTION_NOBEEP,
OPTION_COUNT
} OptionType;
static char *OptionString[OPTION_COUNT] = {"",
"name",
"class",
"gender",
"nap",
"nonap",
"welcome",
"nowelcome",
"enhanced_interface",
"noenhanced_interface",
"beep",
"nobeep"};
/* =============================================================================
* Exported functions
*/
/* =============================================================================
* FUNCTION: newgame
*/
void newgame(void) {
time(&initialtime);
srand((unsigned)initialtime);
}
/* =============================================================================
* FUNCTION: sethard
*/
void sethard(int hard) {
int j, k, i;
if (restorflag == 0) {
/* don't set c[HARDGAME] if restoring game */
if (hashewon() == 0) {
if (hard >= 0)
c[HARDGAME] = hard;
} else if (hard > c[HARDGAME] || wizard)
c[HARDGAME] = hard;
}
k = c[HARDGAME];
if (k != 0) {
for (j = 0; j <= MAXMONST + 8; j++) {
i = ((6 + k) * monster[j].hitpoints + 1) / 6;
monster[j].hitpoints = (short)((i > 32767) ? 32767 : i);
i = ((6 + k) * monster[j].damage + 1) / 5;
monster[j].damage = (char)((i > 127) ? 127 : i);
i = (10 * monster[j].gold) / (10 + k);
monster[j].gold = (short)((i > 32767) ? 32767 : i);
i = monster[j].armorclass - k;
monster[j].armorclass = (char)((i < -127) ? -127 : i);
i = (int)((7 * monster[j].experience) / (7 + k) + 1);
monster[j].experience = (i <= 0) ? 1 : i;
}
}
}
/* =============================================================================
* FUNCTION: read_options
*/
void read_options(void) {
char Line[LINE_LEN + 1];
char *Str;
char *tok;
FILE *fp;
OptionType OptionId;
int Found;
fp = fopen(optsfile, "r");
if (fp == NULL)
/*
* Couldn't open the options file.
*/
return;
while (!feof(fp)) {
Str = fgets(Line, LINE_LEN, fp);
if (Str == NULL) {
/* End of file - do nothng */
} else if (Line[0] == '#') {
/* Comment line - do nothing */
} else {
tok = strtok(Line, " \t\n=");
if (tok == NULL) {
/* A blank line */
} else if (strcmp(tok, "OPTION") == 0) {
/* Read all options specified on this line. */
do {
/* get the option string */
tok = strtok(NULL, ",:\n");
/* identify the option */
if (tok == NULL)
OptionId = OPTION_NULL;
else {
OptionId = OPTION_NAME;
Found = 0;
while ((OptionId < OPTION_COUNT) && (!Found)) {
if (strcmp(OptionString[OptionId], tok) == 0)
Found = 1;
else
OptionId++;
}
}
switch (OptionId) {
case OPTION_NULL:
break;
case OPTION_NAME:
tok = strtok(NULL, ":,\n");
strncpy(logname, tok, LOGNAMESIZE);
break;
case OPTION_CLASS:
tok = strtok(NULL, ":,\n");
char_picked = identify_class(tok);
break;
case OPTION_GENDER:
tok = strtok(NULL, ":,\n");
if (strcmp(tok, "male") == 0)
sex = 1;
else if (strcmp(tok, "female") == 0)
sex = 0;
else
Printf("\nUnknown gender '%s'", tok);
break;
case OPTION_NAP:
nonap = 0;
break;
case OPTION_NONAP:
nonap = 1;
break;
case OPTION_WELCOME:
nowelcome = 0;
break;
case OPTION_NOWELCOME:
nowelcome = 1;
break;
case OPTION_ENHANCE_INT:
enhance_interface = 1;
break;
case OPTION_NOENHANCE_INT:
enhance_interface = 0;
break;
case OPTION_BEEP:
nobeep = 0;
break;
case OPTION_NOBEEP:
nobeep = 1;
break;
default:
Printf("\nUnrecognised option '%s'", tok);
break;
}
} while ((OptionId != OPTION_NULL) && (OptionId < OPTION_COUNT));
} else if (strcmp(tok, "LIBDIR") == 0) {
tok = strtok(NULL, ":\n");
strcpy(libdir, tok);
} else if (strcmp(tok, "SAVEDIR") == 0) {
tok = strtok(NULL, ":\n");
strcpy(savedir, tok);
} else
Printf("\nUnrecognised option '%s'", tok);
}
}
fclose(fp);
}