forked from muspellsson/omega-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomega.c
523 lines (467 loc) · 15.4 KB
/
omega.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
516
517
518
519
520
521
522
523
/* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
/* this file includes main() and some top-level functions */
/* omega.c */
#include "glob.h"
#if !defined(MSDOS_SUPPORTED_ANTIQUE)
#include <signal.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
/* Note: in order to avoid a memory bug I've been told about, I'm
explicitly initializing every global to something. */
#endif
#ifndef NOGETOPT
# include <unistd.h>
#endif
/* most globals originate in omega.c */
char *Omegalib; /* contains the path to the library files */
char *Omegastate; /* contains the path to the volatile files */
#ifdef DEBUG
FILE *DG_debug_log; /* debug log file pointer */
int DG_debug_flag = 0; /* debug flag -- set by -d commandline option */
#endif
char SaveFileName[80];
/* Objects and Monsters are allocated and initialized in init.c */
/* one of each spell */
#ifndef MSDOS_SUPPORTED_ANTIQUE
struct spell Spells[NUMSPELLS+1];
#else
struct spell Spells[NUMSPELLS+1] = {0};
#endif
/* locations of city sites [0] - found, [1] - x, [2] - y */
#ifndef MSDOS_SUPPORTED_ANTIQUE
int CitySiteList[NUMCITYSITES][3];
#else
int CitySiteList[NUMCITYSITES][3] = {0};
#endif
/* Currently defined in caps since it is now a variable, was a constant */
int LENGTH=MAXLENGTH;
int WIDTH=MAXWIDTH;
long GameStatus=0L; /* Game Status bit vector */
int ScreenLength = 0; /* How large is level window */
int ScreenWidth = 0; /* How large is level window */
#ifndef MSDOS_SUPPORTED_ANTIQUE
struct player Player; /* the player */
#else
struct player Player = {0}; /* the player */
#endif
#ifndef MSDOS_SUPPORTED_ANTIQUE
struct terrain Country[COUNTRY_WIDTH][COUNTRY_LENGTH];/* The countryside */
#else
struct terrain Country[COUNTRY_WIDTH][COUNTRY_LENGTH] = {0};/* The countryside */
#endif
#ifdef SAVE_LEVELS
struct level TheLevel;
#endif
struct level *City=NULL; /* The city of Rampart */
struct level *TempLevel=NULL; /* Place holder */
struct level *Level=NULL; /* Pointer to current Level */
struct level *Dungeon=NULL; /* Pointer to current Dungeon */
int Villagenum = 0; /* Current Village number */
int ScreenOffset = 0; /* Offset of displayed screen to level */
int ScreenXOffset = 0; /* Offset of displayed screen to level */
int MaxDungeonLevels = 0; /* Deepest level allowed in dungeon */
int Current_Dungeon= -1; /* What is Dungeon now */
int Current_Environment= E_CITY; /* Which environment are we in */
int Last_Environment= E_COUNTRYSIDE; /* Which environment were we in */
#ifndef MSDOS_SUPPORTED_ANTIQUE
int Dirs[2][9]; /* 9 xy directions */
#else
int Dirs[2][9]= /* 9 xy directions */
{ { 1,1,-1,-1,1,-1,0,0,0} , { 1,-1,1,-1,0,0,1,-1,0 } };
#endif
char Cmd='s'; /* last player command */
int Command_Duration = 0; /* how long does current command take */
struct monster *Arena_Monster=NULL; /* Opponent in arena */
int Arena_Opponent=0; /* case label of opponent in l_arena()*/
int Arena_Victory = 0; /* did player win in arena? */
int Imprisonment=0; /* amount of time spent in jail */
int Precipitation=0; /* Hours of rain, snow, etc */
int Lunarity=0; /* Effect of the moon on character */
int Phase = 0; /* Phase of the moon */
int Date = 0; /* Starting date */
int Pawndate = 0; /* Pawn Shop item generation date */
pob Pawnitems[PAWNITEMS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
/* items in pawn shop */
int SymbolUseHour= -1; /* holy symbol use marker */
int SymbolUseDay= -1; /* holy symbol use marker */
int ViewHour= -1; /* crystal ball use marker */
int ViewDay= -1; /* crystal ball use marker */
int ZapHour= -1; /* staff of enchantment use marker */
int ZapDay= -1; /* staff of enchantment use marker */
int HelmHour= -1; /* helm of teleportation use marker*/
int HelmDay= -1; /* helm of teleportation use marker*/
int Constriction=0; /* Dragonlord Attack State */
int Blessing=FALSE; /* Altar Blessing State */
int LastDay= -1; /* DPW date of dole */
int RitualHour= -1; /* last use of ritual magic */
int RitualRoom= -1; /* last room of ritual magic */
int Lawstone=0; /* magic stone counter */
int Chaostone=0; /* magic stone counter */
int Mindstone=0; /* magic stone counter */
int Searchnum = 1; /* number of times to search on 's' */
int Behavior; /* Player NPC behavior */
int Verbosity = VERBOSE; /* verbosity level */
long Time = 0; /* turn number */
int Tick = 0; /* 10 a turn; action coordinator */
char Stringbuffer[STRING_BUFFER_SIZE][80]; /* last strings printed */
long Gymcredit = 0; /* credit at rampart gym */
int Spellsleft = 0; /* research allowance at college */
int SalaryAmount = 0; /* legion salary */
int SalaryAccount = 0; /* account number to which legion salary is paid */
int Studiesleft = 0; /* study allowance at monastery */
int StarGemUse = 0; /* last date of star gem use */
int HiMagicUse = 0; /* last date of high magic use */
int HiMagic = 0; /* current level for l_throne */
#ifdef NEW_BANK
bank_account *bank = NULL; /* ptr to a list of bank accounts */
#else
long Balance = 0; /* bank account */
#endif
long FixedPoints = 0; /* points are frozen after adepthood*/
int LastTownLocX=0; /* previous position in village or city */
int LastTownLocY=0; /* previous position in village or city */
int LastCountryLocX=0; /* previous position in countryside */
int LastCountryLocY=0; /* previous position in countryside */
#ifndef NEW_BANK
#ifndef MSDOS_SUPPORTED_ANTIQUE
char Password[64]; /* autoteller password */
#else
char Password[64] = {0}; /* autoteller password */
#endif
#endif
#ifndef MSDOS_SUPPORTED_ANTIQUE
char Str1[STRING_LEN],Str2[STRING_LEN],Str3[STRING_LEN],Str4[STRING_LEN];
#else
char Str1[STRING_LEN] = {0},Str2[STRING_LEN] = {0},Str3[STRING_LEN] = {0},Str4[STRING_LEN] = {0};
#endif
/* Some string space, random uses */
pol Condoitems=NULL; /* Items in condo */
pol Bagitems=NULL; /* Items in bag of holding */
/* high score names, levels, behavior */
#ifndef MSDOS_SUPPORTED_ANTIQUE
int Shadowlordbehavior,Archmagebehavior,Primebehavior,Commandantbehavior;
int Championbehavior,Priestbehavior[7],Hibehavior,Dukebehavior;
int Chaoslordbehavior,Lawlordbehavior,Justiciarbehavior;
int Grandmasterbehavior;
int Grandmasterlevel;
char Grandmaster[80];
char Shadowlord[80],Archmage[80],Prime[80],Commandant[80],Duke[80];
char Champion[80],Priest[7][80],Hiscorer[80],Hidescrip[80];
char Chaoslord[80],Lawlord[80],Justiciar[80];
int Shadowlordlevel,Archmagelevel,Primelevel,Commandantlevel,Dukelevel;
#else
int Grandmasterbehavior = 0;
int Grandmasterlevel = 0;
char Grandmaster[80] = {0};
int Shadowlordbehavior = 0,Archmagebehavior = 0,Primebehavior = 0,Commandantbehavior = 0;
int Championbehavior = 0,Priestbehavior[7] = {0},Hibehavior = 0,Dukebehavior = 0;
int Chaoslordbehavior = 0,Lawlordbehavior = 0,Justiciarbehavior = 0;
char Shadowlord[80] = {0},Archmage[80] = {0},Prime[80] = {0},Commandant[80] = {0},Duke[80] = {0};
char Champion[80] = {0},Priest[7][80] = {0},Hiscorer[80] = {0},Hidescrip[80] = {0};
char Chaoslord[80] = {0},Lawlord[80] = {0},Justiciar[80] = {0};
int Shadowlordlevel = 0,Archmagelevel = 0,Primelevel = 0,Commandantlevel = 0,Dukelevel = 0;
#endif
#ifndef MSDOS_SUPPORTED_ANTIQUE
int Championlevel,Priestlevel[7],Hilevel,Justiciarlevel;
#else
int Championlevel = 0,Priestlevel[7] = {0},Hilevel = 0,Justiciarlevel = 0;
#endif
long Hiscore = 0L;
int Chaoslordlevel = 0,Lawlordlevel = 0,Chaos = 0,Law = 0;
/* New globals which used to be statics */
int twiddle = FALSE;
int saved=FALSE;
int onewithchaos=FALSE;
int club_hinthour = 0;
int winnings = 0;
int tavern_hinthour = -1;
int scroll_ids[30];
int potion_ids[30];
int stick_ids[30];
int ring_ids[30];
int cloak_ids[30];
int boot_ids[30];
int deepest[E_MAX + 1];
int level_seed[E_MAX + 1]; /* random number seed that generated level */
/* This may be implementation dependent */
/* SRANDFUNCTION is defined in odefs.h */
/* environment is the environment about to be generated, or -1 for the first */
/* time, or -2 if we want to restore the random number point */
void initrand(int environment, int level)
{
static int store;
int seed;
if (environment >= 0)
store = RANDFUNCTION();
/* Pseudo Random Seed */
if (environment == E_RANDOM)
seed = (int) time(NULL);
else if (environment == E_RESTORE)
seed = store;
else
seed = level_seed[environment] + 1000*level;
SRANDFUNCTION(seed);
}
int game_restore(char *savefile)
{
int ok;
ok = restore_game(savefile);
if (! ok) {
endgraf();
printf("Try again with the right save file, luser!\n");
exit(1);
}
change_to_user_perms();
unlink(savefile);
change_to_game_perms();
return(TRUE);
}
void signalquit(int ignore)
{
quit();
}
int main(int argc, char *argv[])
{
int continuing = 0;
int count;
int scores_only = 0;
int i;
#ifndef NOGETOPT
while(( i= getopt( argc, argv, "dsh")) != -1)
{
switch (i)
{
case 'd':
#ifdef DEBUG
DG_debug_flag++;
#endif
break;
case 's':
scores_only = 1;
break;
case 'h':
#ifdef DEBUG
printf("Usage: omega [-shd] [savefile]\n");
#else
printf("Usage: omega [-sh] [savefile]\n");
#endif
printf("Options:\n");
printf(" -s Display high score list\n");
printf(" -h Display this message\n");
#ifdef DEBUG
printf(" -d Enable debug mode\n");
#endif
exit(0);
break;
case '?':
/* error parsing args... ignore? */
printf("'%c' is an invalid option, ignoring\n", optopt );
break;
}
}
if (optind >= argc ) {
/* no save file given */
#if defined( BSD ) || defined( SYSV )
sprintf( SaveFileName, "Omega%d", getuid() );
#else
strcpy( SaveFileName,"Omega");
#endif
} else {
/* savefile given */
continuing = 1;
strcpy(SaveFileName,argv[optind]);
}
#else
/* alternate code for people who don't support getopt() -- no enhancement */
if (argc ==2) {
strcpy( SaveFileName, argv[1]);
continuing = 1;
} else {
strcpy( SaveFileName,"Omega");
}
#endif
/* always catch ^c and hang-up signals */
#ifdef SIGINT
signal(SIGINT,signalquit);
#endif
#ifdef SIGHUP
signal(SIGHUP,signalsave);
#endif
#ifndef MSDOS
if (CATCH_SIGNALS) {
signal(SIGQUIT,signalexit);
signal(SIGILL,signalexit);
#ifdef DEBUG
if( DG_debug_flag ) {
#endif
signal(SIGTRAP,signalexit);
signal(SIGFPE,signalexit);
signal(SIGSEGV,signalexit);
#ifdef DEBUG
}
#endif
#ifdef SIGIOT
signal(SIGIOT,signalexit);
#endif
#ifdef SIGABRT
signal(SIGABRT,signalexit);
#endif
#ifdef SIGEMT
signal(SIGEMT,signalexit);
#endif
#ifdef SIGBUS
signal(SIGBUS,signalexit);
#endif
#ifdef SIGSYS
signal(SIGSYS,signalexit);
#endif
}
#endif
#ifndef FIXED_OMEGALIB
if (!(Omegalib = getenv("OMEGALIB")))
#endif
Omegalib = OMEGALIB;
Omegastate = OMEGASTATE;
/* if filecheck is 0, some necessary data files are missing */
if (filecheck() == 0) exit(0);
/* all kinds of initialization */
init_perms();
initgraf();
#ifndef MSDOS_SUPPORTED_ANTIQUE
initdirs();
#endif
initrand(E_RANDOM, 0);
initspells();
#ifdef DEBUG
/* initialize debug log file */
DG_debug_log = fopen( "/tmp/omega_dbg_log", "a" );
assert( DG_debug_log ); /* WDT :) */
setvbuf( DG_debug_log, NULL, _IOLBF, 0);
fprintf(DG_debug_log, "############## new game started ##############\n");
#endif
for (count = 0; count < STRING_BUFFER_SIZE; count++)
strcpy(Stringbuffer[count],"<nothing>");
#ifdef SAVE_LEVELS
msdos_init();
#endif
omega_title();
showscores();
if (scores_only ) {
endgraf();
exit(0);
}
/* game restore attempts to restore game if there is an argument */
if (continuing)
{
game_restore(SaveFileName);
mprint("Your adventure continues....");
}
else
{
/* monsters initialized in game_restore if game is being restored */
/* items initialized in game_restore if game is being restored */
inititem(TRUE);
Date = random_range(360);
Phase = random_range(24);
#ifdef NEW_BANK
bank_init();
#else
strcpy(Password,"");
#endif
continuing = initplayer(); /* RM: 04-19-2000 loading patch */
}
if (!continuing)
{
init_world(); /* RM: 04-19-2000 loading patch */
mprint("'?' for help or commandlist, 'Q' to quit.");
}
timeprint();
calc_melee();
if (Current_Environment != E_COUNTRYSIDE)
showroom(Level->site[Player.x][Player.y].roomnumber);
else
terrain_check(FALSE);
if (optionp(SHOW_COLOUR))
colour_on();
else
colour_off();
screencheck(Player.x,Player.y);
/* game cycle */
if (!continuing)
time_clock(TRUE);
while (TRUE) {
if (Current_Environment == E_COUNTRYSIDE)
p_country_process();
else time_clock(FALSE);
}
}
#ifndef MSDOS
void signalexit(int ignored)
{
clearmsg();
mprint("Yikes!");
morewait();
mprint("Sorry, caught a core-dump signal.");
#if 0
/* DAG used to prompt... space-bar holding through messages could cause
* failure to save. Now always just force through with signalsave() */
mprint("Want to try and save the game?");
reply = ynq();
if (reply=='y')
save(FALSE, TRUE); /* don't compress, force save */
else if (reply == EOF)
signalsave(0);
#else
signalsave(0);
#endif
endgraf();
printf("Bye!\n");
exit(0);
}
#endif
/* Start up game with new dungeons; start with player in city */
void init_world(void)
{
int env, i;
City = Level = TempLevel = Dungeon = NULL;
for (env = 0; env <= E_MAX; env++)
level_seed[env] = RANDFUNCTION();
load_country();
for(i=0;i<NUMCITYSITES;i++)
CitySiteList[i][0] = FALSE;
load_city(TRUE);
Level = City;
Current_Environment = E_CITY;
setPlayerXY(62, 20);
print1("You pass through the massive gates of Rampart, the city.");
screencheck(Player.x, Player.y);
}
/* set variable item names */
void inititem(int reset)
{
int i;
if (reset) {
shuffle(scroll_ids, 30);
shuffle(potion_ids, 20);
shuffle(stick_ids, 20);
shuffle(boot_ids, 20);
shuffle(cloak_ids, 20);
shuffle(ring_ids, 20);
}
for(i=0;i<NUMSCROLLS;i++)
Objects[SCROLLID+i].objstr = scrollname(i);
for(i=0;i<NUMPOTIONS;i++)
Objects[POTIONID+i].objstr = potionname(i);
Objects[OB_POTION_DEATH].objstr = potionname(18);
Objects[OB_POTION_LIFE].objstr = potionname(19);
for(i=0;i<NUMSTICKS;i++)
Objects[STICKID+i].objstr = stickname(i);
for(i=0;i<NUMBOOTS;i++)
Objects[BOOTID+i].objstr = bootname(i);
for(i=0;i<NUMCLOAKS;i++)
Objects[CLOAKID+i].objstr = cloakname(i);
for(i=0;i<NUMRINGS;i++)
Objects[RINGID+i].objstr = ringname(i);
}