-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
515 lines (465 loc) · 10.6 KB
/
main.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*
* Rogue
* Exploring the dungeons of doom
* Copyright (C) 1980 by Michael Toy and Glenn Wichman
* All rights reserved
*
* @(#)main.c 3.27 (Berkeley) 6/15/81
*/
//#include <curses.h>
//#include <signal.h>
//#include <pwd.h>
//#include "mach_dep.h"
#include "rogue.h"
#include "new_level.h"
#include "curses.h"
#include <conio.h>
#include <apple2enh.h>
#include "random.h"
#include "chase.h"
#include "command.h"
#include "io.h"
//char *EIGHTY_COLUMN = 0xC00D;
char *ENABLE_LC_BANK1 = 0xC083;
//#pragma bss-name(push, "LC")
//char blah[0x0C00];
//#pragma bss-name("LC")
//#ifdef CHECKTIME
//static int num_checks; /* times we've gone over in checkout() */
//#endif
void playit(void);
void main(void)
{
// register char *env;
// register struct passwd *pw;
// register struct linked_list *item;
// register struct object *obj;
// struct passwd *getpwuid();
// char *getpass(), *crypt();
// int quit(), lowtime;
// long now;
char key_pressed;
clrscr();
cw = &play_window;
mw = &monster_window;
stdscr = &dungeon_window;
videomode((unsigned char) 80);
clrscr();
while(1) {
/*
* check for print-score option
*/
// if (argc == 2 && strcmp(argv[1], "-s") == 0)
// {
// waswizard = TRUE;
// score(0, -1);
// exit(0);
// }
/*
* Check to see if he is a wizard
*/
// if (argc >= 2 && argv[1][0] == '\0')
// if (strcmp(PASSWD, crypt(getpass("Wizard's password: "), "mT")) == 0)
// {
// wizard = TRUE;
// argv++;
// argc--;
// }
/*
* get home and options from environment
*/
// if ((env = getenv("HOME")) != NULL)
// strcpy(home, env);
// else if ((pw = getpwuid(getuid())) != NULL)
// strcpy(home, pw->pw_dir);
// else
// home[0] = '\0';
// strcat(home, "/");
// strcpy(file_name, home);
// strcat(file_name, "rogue.save");
// if ((env = getenv("ROGUEOPTS")) != NULL)
// parse_opts(env);
// if (env == NULL || whoami[0] == '\0') {
// if ((pw = getpwuid(getuid())) == NULL) {
// printf("Say, who the hell are you?\n");
// exit(1);
// } else {
// strucpy(whoami, pw->pw_name, strlen(pw->pw_name));
// }
// }
// if (env == NULL || fruit[0] == '\0')
// strcpy(fruit, "slime-mold");
//#if MAXLOAD|MAXUSERS
// if (too_much() && !wizard && !author())
// {
// printf("Sorry, %s, but the system is too loaded now.\n", whoami);
// printf("Try again later. Meanwhile, why not enjoy a%s %s?\n",
// vowelstr(fruit), fruit);
// exit(1);
// }
//#endif
// if (argc == 2)
// if (!restore(argv[1], envp)) /* Note: restore will never return */
// exit(1);
// time(&now);
// lowtime = (int) now;
// dnum = (wizard && getenv("SEED") != NULL ?
// atoi(getenv("SEED")) :
// lowtime + getpid());
// if (wizard)
// printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
// else
// printf("Hello %s, just a moment while I dig the dungeon...", whoami);
// fflush(stdout);
// seed = dnum;
// init_player(); /* Roll up the rogue */
// init_things(); /* Set up probabilities of things */
// init_names(); /* Set up names of scrolls */
// init_colors(); /* Set up colors of potions */
// init_stones(); /* Set up stone settings of rings */
// init_materials(); /* Set up materials of wands */
// initscr(); /* Start up cursor package */
// setup();
/*
* Set up windows
*/
// cw = newwin(LINES, COLS, 0, 0);
// play_window = {0, 0, {0}};
// mw = newwin(LINES, COLS, 0, 0);
// hw = newwin(LINES, COLS, 0, 0);
// waswizard = wizard;
//new_level(); /* Draw current level */
/*
* Start up daemons and fuses
*/
// daemon(doctor, 0, AFTER);
// fuse(swander, 0, WANDERTIME, AFTER);
// daemon(stomach, 0, AFTER);
// daemon(runners, 0, AFTER);
/*
* Give the rogue his weaponry. First a mace.
*/
// item = new_item(sizeof *obj);
// obj = (struct object *) ldata(item);
// obj->o_type = WEAPON;
// obj->o_which = MACE;
// init_weapon(obj, MACE);
// obj->o_hplus = 1;
// obj->o_dplus = 1;
// obj->o_flags |= ISKNOW;
// add_pack(item, TRUE);
// cur_weapon = obj;
/*
* Now a +1 bow
*/
// item = new_item(sizeof *obj);
// obj = (struct object *) ldata(item);
// obj->o_type = WEAPON;
// obj->o_which = BOW;
// init_weapon(obj, BOW);
// obj->o_hplus = 1;
// obj->o_dplus = 0;
// obj->o_flags |= ISKNOW;
// add_pack(item, TRUE);
/*
* Now some arrows
*/
// item = new_item(sizeof *obj);
// obj = (struct object *) ldata(item);
// obj->o_type = WEAPON;
// obj->o_which = ARROW;
// init_weapon(obj, ARROW);
// obj->o_count = 25+rnd(15);
// obj->o_hplus = obj->o_dplus = 0;
// obj->o_flags |= ISKNOW;
// add_pack(item, TRUE);
/*
* And his suit of armor
*/
// item = new_item(sizeof *obj);
// obj = (struct object *) ldata(item);
// obj->o_type = ARMOR;
// obj->o_which = RING_MAIL;
// obj->o_ac = a_class[RING_MAIL] - 1;
// obj->o_flags |= ISKNOW;
// cur_armor = obj;
// add_pack(item, TRUE);
/*
* Give him some food too
*/
// item = new_item(sizeof *obj);
// obj = (struct object *) ldata(item);
// obj->o_type = FOOD;
// obj->o_count = 1;
// obj->o_which = 0;
// add_pack(item, TRUE);
// playit();
key_pressed = cgetc();
switch (key_pressed) {
case '3':
show_window(mw);
break;
case 'p':
show_window(cw);
playit();
break;
case 'n':
level++;
hungry_state = rnd(4);
purse = 0;
new_level();
break;
case '2':
show_window(stdscr);
break;
case '1':
show_window(cw);
default:
break;
}
}
}
/*
* endit:
* Exit the program abnormally.
*/
//endit()
//{
// fatal("Ok, if you want to exit that badly, I'll have to allow it\n");
//}
/*
* fatal:
* Exit the program, printing a message.
*/
//fatal(s)
//char *s;
//{
// clear();
// move(LINES-2, 0);
// printw("%s", s);
// draw(stdscr);
// endwin();
// exit(0);
//}
/*
* rnd:
* Pick a very random number.
*/
//int rnd(int range)
//{
// return range == 0 ? 0 : abs(RN) % range;
//}
//# ifdef SIGTSTP
/*
* handle stop and start signals
*/
//tstp()
//{
// mvcur(0, COLS - 1, LINES - 1, 0);
// endwin();
// fflush(stdout);
// kill(0, SIGTSTP);
// signal(SIGTSTP, tstp);
// crmode();
// noecho();
// clearok(curscr, TRUE);
// touchwin(cw);
// draw(cw);
// raw(); /* flush input */
// noraw();
//}
//# endif
//
//setup()
//{
//#ifdef CHECKTIME
// int checkout();
//#endif
//#ifndef DUMP
// signal(SIGHUP, auto_save);
// signal(SIGILL, auto_save);
// signal(SIGTRAP, auto_save);
// signal(SIGIOT, auto_save);
// signal(SIGEMT, auto_save);
// signal(SIGFPE, auto_save);
// signal(SIGBUS, auto_save);
// signal(SIGSEGV, auto_save);
// signal(SIGSYS, auto_save);
// signal(SIGPIPE, auto_save);
// signal(SIGTERM, auto_save);
//#endif
//
// signal(SIGINT, quit);
//#ifndef DUMP
// signal(SIGQUIT, endit);
//#endif
//#ifdef SIGTSTP
// signal(SIGTSTP, tstp);
//#endif
//#ifdef CHECKTIME
// if (!author())
// {
// signal(SIGALRM, checkout);
// alarm(CHECKTIME * 60);
// num_checks = 0;
// }
//#endif
// crmode(); /* Cbreak mode */
// noecho(); /* Echo off */
//}
/*
* playit:
* The main loop of the program. Loop until the game is over,
* refreshing things and looking at the proper times.
*/
void playit(void)
{
// register char *opts;
/*
* set up defaults for slow terminals
*/
// if (_tty.sg_ospeed < B1200)
// {
// terse = TRUE;
// jump = TRUE;
// }
//
// /*
// * parse environment declaration of options
// */
// if ((opts = getenv("ROGUEOPTS")) != NULL)
// parse_opts(opts);
oldpos = hero;
oldrp = roomin(&hero);
while (playing) {
command(); /* Command execution */
}
//endit();
}
//#if MAXLOAD|MAXUSERS
/*
* see if the system is being used too much for this game
*/
//too_much()
//{
//#ifdef MAXLOAD
// double avec[3];
//#else
// register int cnt;
//#endif
//
//#ifdef MAXLOAD
// loadav(avec);
// return (avec[2] > (MAXLOAD / 10.0));
//#else
// return (ucount() > MAXUSERS);
//#endif
//}
/*
* see if a user is an author of the program
*/
//author()
//{
// switch (getuid())
// {
// case 24601:
// return TRUE;
// default:
// return FALSE;
// }
//}
//#endif
//#ifdef CHECKTIME
//checkout()
//{
// static char *msgs[] = {
// "The load is too high to be playing. Please leave in %d minutes",
// "Please save your game. You have %d minutes",
// "Last warning. You have %d minutes to leave",
// };
// int checktime;
//
// signal(SIGALRM, checkout);
// if (too_much())
// {
// if (num_checks == 3)
// fatal("Sorry. You took to long. You are dead\n");
// checktime = CHECKTIME / (num_checks + 1);
// chmsg(msgs[num_checks++], checktime);
// alarm(checktime * 60);
// }
// else
// {
// if (num_checks)
// {
// chmsg("The load has dropped back down. You have a reprieve.");
// num_checks = 0;
// }
// alarm(CHECKTIME * 60);
// }
//}
/*
* checkout()'s version of msg. If we are in the middle of a shell, do a
* printf instead of a msg to avoid the refresh.
*/
//chmsg(fmt, arg)
//char *fmt;
//int arg;
//{
// if (in_shell)
// {
// printf(fmt, arg);
// putchar('\n');
// fflush(stdout);
// }
// else
// msg(fmt, arg);
//}
//#endif
//#ifdef LOADAV
//#include <nlist.h>
//struct nlist avenrun =
//{
// "_avenrun"
//};
//loadav(avg)
//register double *avg;
//{
// register int kmem;
//
// if ((kmem = open("/dev/kmem", 0)) < 0)
// goto bad;
// nlist(NAMELIST, &avenrun);
// if (avenrun.n_type == 0)
// {
//bad:
// avg[0] = avg[1] = avg[2] = 0.0;
// return;
// }
//
// lseek(kmem, (long) avenrun.n_value, 0);
// read(kmem, avg, 3 * sizeof (double));
//}
//#endif
//#ifdef UCOUNT
//#include <utmp.h>
//struct utmp buf;
//ucount()
//{
// register struct utmp *up;
// register FILE *utmp;
// register int count;
//
// if ((utmp = fopen(UTMP, "r")) == NULL)
// return 0;
//
// up = &buf;
// count = 0;
//
// while (fread(up, 1, sizeof (*up), utmp) > 0)
// if (buf.ut_name[0] != '\0')
// count++;
// fclose(utmp);
// return count;
//}
//#endif