1 /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
2 /* country.c */
3 /* load_country(), and all load_ functions for places which are */
4 /* accessible from the country and don't have their own files */
5 
6 #include "glob.h"
7 
8 /* loads the countryside level from the data file */
load_country()9 void load_country()
10 {
11   int i,j;
12   char site;
13 
14   FILE *fd;
15 
16   strcpy(Str3,Omegalib);
17   strcat(Str3,"country.dat");
18   fd = checkfopen(Str3,"rb");
19   site = cryptkey("country.dat");
20 
21   for(j=0;j<LENGTH;j++) {
22     for(i=0;i<WIDTH;i++) {
23       site = getc(fd)^site;
24       Country[i][j].aux = 0;
25       Country[i][j].status = 0;
26       switch (site) {
27 	case (PASS&0xff):
28 	  Country[i][j].base_terrain_type = PASS;
29 	  Country[i][j].current_terrain_type = MOUNTAINS;
30 	  break;
31 	case (CASTLE&0xff):
32 	  Country[i][j].base_terrain_type = CASTLE;
33 	  Country[i][j].current_terrain_type = MOUNTAINS;
34 	  break;
35 	case (STARPEAK&0xff):
36 	  Country[i][j].base_terrain_type = STARPEAK;
37 	  Country[i][j].current_terrain_type = MOUNTAINS;
38 	  break;
39 	case (CAVES&0xff):
40 	  Country[i][j].base_terrain_type = CAVES;
41 	  Country[i][j].current_terrain_type = MOUNTAINS;
42 	  break;
43 	case (VOLCANO&0xff):
44 	  Country[i][j].base_terrain_type = VOLCANO;
45 	  Country[i][j].current_terrain_type = MOUNTAINS;
46 	  break;
47 	case (DRAGONLAIR&0xff):
48 	  Country[i][j].base_terrain_type = DRAGONLAIR;
49 	  Country[i][j].current_terrain_type = DESERT;
50 	  break;
51 	case (MAGIC_ISLE&0xff):
52 	  Country[i][j].base_terrain_type = MAGIC_ISLE;
53 	  Country[i][j].current_terrain_type = CHAOS_SEA;
54 	  break;
55 	case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
56 	  Country[i][j].current_terrain_type =
57 	    Country[i][j].base_terrain_type = VILLAGE;
58 	  Country[i][j].aux = 1+site-'a';
59 	  break;
60 	case '1': case '2': case '3': case '4': case '5': case '6':
61 	  Country[i][j].current_terrain_type =
62 	    Country[i][j].base_terrain_type = TEMPLE;
63 	  Country[i][j].aux = site-'0';
64 	  break;
65 	case (PLAINS&0xff):
66 	  Country[i][j].current_terrain_type =
67 	      Country[i][j].base_terrain_type = PLAINS;
68 	  break;
69 	case (TUNDRA&0xff):
70 	  Country[i][j].current_terrain_type =
71 	      Country[i][j].base_terrain_type = TUNDRA;
72 	  break;
73 	case (ROAD&0xff):
74 	  Country[i][j].current_terrain_type =
75 	      Country[i][j].base_terrain_type = ROAD;
76 	  break;
77 	case (MOUNTAINS&0xff):
78 	  Country[i][j].current_terrain_type =
79 	      Country[i][j].base_terrain_type = MOUNTAINS;
80 	  break;
81 	case (RIVER&0xff):
82 	  Country[i][j].current_terrain_type =
83 	      Country[i][j].base_terrain_type = RIVER;
84 	  break;
85 	case (CITY&0xff):
86 	  Country[i][j].current_terrain_type =
87 	      Country[i][j].base_terrain_type = CITY;
88 	  break;
89 	case (FOREST&0xff):
90 	  Country[i][j].current_terrain_type =
91 	      Country[i][j].base_terrain_type = FOREST;
92 	  break;
93 	case (JUNGLE&0xff):
94 	  Country[i][j].current_terrain_type =
95 	      Country[i][j].base_terrain_type = JUNGLE;
96 	  break;
97 	case (SWAMP&0xff):
98 	  Country[i][j].current_terrain_type =
99 	      Country[i][j].base_terrain_type = SWAMP;
100 	  break;
101 	case (DESERT&0xff):
102 	  Country[i][j].current_terrain_type =
103 	      Country[i][j].base_terrain_type = DESERT;
104 	  break;
105 	case (CHAOS_SEA&0xff):
106 	  Country[i][j].current_terrain_type =
107 	      Country[i][j].base_terrain_type = CHAOS_SEA;
108 	  break;
109       }
110     }
111     site = getc(fd)^site;
112   }
113   fclose(fd);
114 }
115 
116 
117 
118 
119 
120 
121 
122 /* loads the dragon's lair into Level*/
load_dlair(empty,populate)123 void load_dlair(empty, populate)
124 int empty;
125 int populate;
126 {
127   int i,j;
128   char site;
129 
130   FILE *fd;
131 
132   if (empty) {
133     mprint("The Lair is now devoid of inhabitants and treasure.");
134     morewait();
135   }
136 
137   if (!populate)
138     empty = TRUE;
139   TempLevel = Level;
140   if (ok_to_free(TempLevel)) {
141 #ifndef SAVE_LEVELS
142     free_level(TempLevel);
143 #endif
144     TempLevel = NULL;
145   }
146 #ifndef SAVE_LEVELS
147   Level = ((plv) checkmalloc(sizeof(levtype)));
148 #else
149   msdos_changelevel(TempLevel,0,-1);
150   Level = &TheLevel;
151 #endif
152   clear_level(Level);
153   Level->environment = E_DLAIR;
154   strcpy(Str3,Omegalib);
155   strcat(Str3,"dlair.dat");
156   fd = checkfopen(Str3,"rb");
157   site = cryptkey("dlair.dat");
158   for(j=0;j<LENGTH;j++) {
159     for(i=0;i<WIDTH;i++) {
160       Level->site[i][j].lstatus = 0;
161       if (i < 48)
162 	Level->site[i][j].roomnumber = RS_CAVERN;
163       else
164 	Level->site[i][j].roomnumber = RS_DRAGONLORD;
165       Level->site[i][j].p_locf = L_NO_OP;
166       site = getc(fd)^site;
167       switch(site) {
168       case 'D':
169 	Level->site[i][j].locchar = FLOOR;
170 	if (! empty) {
171 	  make_site_monster(i,j,DRAGON_LORD);
172 	  Level->site[i][j].creature->specialf = M_SP_LAIR;
173 	}
174 	break;
175       case 'd':
176 	Level->site[i][j].locchar = FLOOR;
177 	if (! empty) {
178 	  make_site_monster(i,j,DRAGON); /* elite dragons, actually */
179 	  Level->site[i][j].creature->specialf = M_SP_LAIR;
180 	  Level->site[i][j].creature->hit *= 2;
181 	  Level->site[i][j].creature->dmg *= 2;
182 	}
183 	break;
184       case 'W':
185 	Level->site[i][j].locchar = FLOOR;
186 	if (! empty)
187 	  make_site_monster(i,j,KING_WYV);
188 	break;
189       case 'M':
190 	Level->site[i][j].locchar = FLOOR;
191 	if (! empty)
192 	  make_site_monster(i,j,RANDOM);
193 	break;
194       case 'S':
195 	Level->site[i][j].locchar = FLOOR;
196 	Level->site[i][j].showchar = WALL;
197 	if (! empty)
198 	  lset(i,j,SECRET);
199 	Level->site[i][j].roomnumber = RS_SECRETPASSAGE;
200 	break;
201       case '$':
202 	Level->site[i][j].locchar = FLOOR;
203 	if (! empty)
204 	  make_site_treasure(i,j,10);
205 	break;
206       case 's':
207 	Level->site[i][j].locchar = FLOOR;
208 	Level->site[i][j].p_locf = L_TRAP_SIREN;
209 	break;
210       case '7':
211 	if (! empty)
212 	  Level->site[i][j].locchar = PORTCULLIS;
213 	else Level->site[i][j].locchar = FLOOR;
214 	Level->site[i][j].p_locf = L_PORTCULLIS;
215 	break;
216       case 'R':
217 	Level->site[i][j].locchar = FLOOR;
218 	Level->site[i][j].p_locf = L_RAISE_PORTCULLIS;
219 	break;
220       case 'p':
221 	Level->site[i][j].locchar = FLOOR;
222 	Level->site[i][j].p_locf = L_PORTCULLIS;
223 	break;
224       case 'T':
225 	Level->site[i][j].locchar = FLOOR;
226 	if (! empty)
227 	  Level->site[i][j].p_locf = L_PORTCULLIS_TRAP;
228 	break;
229       case 'X':
230 	Level->site[i][j].locchar = FLOOR;
231 	Level->site[i][j].p_locf = L_TACTICAL_EXIT;
232 	break;
233       case '#':
234 	Level->site[i][j].locchar = WALL;
235 	Level->site[i][j].aux = 150;
236 	break;
237       case '.':
238 	Level->site[i][j].locchar = FLOOR;
239 	break;
240       }
241     }
242     site = getc(fd)^site;
243   }
244   fclose(fd);
245 }
246 
247 
248 
249 
250 
251 /* loads the star peak into Level*/
load_speak(empty,populate)252 void load_speak(empty, populate)
253 int empty;
254 int populate;
255 {
256   int i,j,safe = Player.alignment > 0;
257   char site;
258 
259   FILE *fd;
260 
261   if (empty) {
262     mprint("The peak is now devoid of inhabitants and treasure.");
263     morewait();
264   }
265 
266   if (!populate)
267     empty = TRUE;
268 
269   TempLevel = Level;
270   if (ok_to_free(TempLevel)) {
271 #ifndef SAVE_LEVELS
272     free_level(TempLevel);
273 #endif
274     TempLevel = NULL;
275   }
276 #ifndef SAVE_LEVELS
277   Level = ((plv) checkmalloc(sizeof(levtype)));
278 #else
279   msdos_changelevel(TempLevel,0,-1);
280   Level = &TheLevel;
281 #endif
282   clear_level(Level);
283   Level->environment = E_STARPEAK;
284   strcpy(Str3,Omegalib);
285   strcat(Str3,"speak.dat");
286   fd = checkfopen(Str3,"rb");
287   site = cryptkey("speak.dat");
288   for(j=0;j<LENGTH;j++) {
289     for(i=0;i<WIDTH;i++) {
290       Level->site[i][j].lstatus = 0;
291       Level->site[i][j].roomnumber = RS_STARPEAK;
292       Level->site[i][j].p_locf = L_NO_OP;
293       site = getc(fd)^site;
294       switch(site) {
295       case 'S':
296 	Level->site[i][j].locchar = FLOOR;
297 	Level->site[i][j].showchar = WALL;
298 	lset(i,j,SECRET);
299 	Level->site[i][j].roomnumber = RS_SECRETPASSAGE;
300 	break;
301       case 'L':
302 	Level->site[i][j].locchar = FLOOR;
303 	if (! empty) {
304 	  make_site_monster(i,j,LAWBRINGER);
305 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
306 	}
307 	break;
308       case 's':
309 	Level->site[i][j].locchar = FLOOR;
310 	if (! empty) {
311 	  make_site_monster(i,j,SERV_LAW); /* servant of law */
312 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
313 	}
314 	break;
315       case 'M':
316 	Level->site[i][j].locchar = FLOOR;
317 	if (! empty) {
318 	  make_site_monster(i,j,-1);
319 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
320 	}
321 	break;
322       case '$':
323 	Level->site[i][j].locchar = FLOOR;
324 	if (! empty)
325 	  make_site_treasure(i,j,10);
326 	break;
327       case '7':
328 	if (! empty)
329 	  Level->site[i][j].locchar = PORTCULLIS;
330 	else Level->site[i][j].locchar = FLOOR;
331 	Level->site[i][j].p_locf = L_PORTCULLIS;
332 	break;
333       case 'R':
334 	Level->site[i][j].locchar = FLOOR;
335 	Level->site[i][j].p_locf = L_RAISE_PORTCULLIS;
336 	break;
337       case '-':
338 	Level->site[i][j].locchar = CLOSED_DOOR;
339 	break;
340       case '|':
341 	Level->site[i][j].locchar = OPEN_DOOR;
342 	break;
343       case 'p':
344 	Level->site[i][j].locchar = FLOOR;
345 	Level->site[i][j].p_locf = L_PORTCULLIS;
346 	break;
347       case 'T':
348 	Level->site[i][j].locchar = FLOOR;
349 	if (! empty)
350 	  Level->site[i][j].p_locf = L_PORTCULLIS_TRAP;
351 	break;
352       case 'X':
353 	Level->site[i][j].locchar = FLOOR;
354 	Level->site[i][j].p_locf = L_TACTICAL_EXIT;
355 	break;
356       case '#':
357 	Level->site[i][j].locchar = WALL;
358 	Level->site[i][j].aux = 150;
359 	break;
360       case '4':
361 	Level->site[i][j].locchar = RUBBLE;
362 	Level->site[i][j].p_locf = L_RUBBLE;
363 	break;
364       case '.':
365 	Level->site[i][j].locchar = FLOOR;
366 	break;
367       }
368     }
369     site = getc(fd)^site;
370   }
371   fclose(fd);
372 }
373 
374 
375 
376 /* loads the magic isle into Level*/
load_misle(empty,populate)377 void load_misle(empty, populate)
378 int empty;
379 int populate;
380 {
381   int i,j;
382   char site;
383 
384   FILE *fd;
385 
386   if (empty) {
387     mprint("The isle is now devoid of inhabitants and treasure.");
388     morewait();
389   }
390 
391   if (!populate)
392     empty = TRUE;
393 
394   TempLevel = Level;
395   if (ok_to_free(TempLevel)) {
396 #ifndef SAVE_LEVELS
397     free_level(TempLevel);
398 #endif
399     TempLevel = NULL;
400   }
401 #ifndef SAVE_LEVELS
402   Level = ((plv) checkmalloc(sizeof(levtype)));
403 #else
404   msdos_changelevel(TempLevel,0,-1);
405   Level = &TheLevel;
406 #endif
407   clear_level(Level);
408   Level->environment = E_MAGIC_ISLE;
409   strcpy(Str3,Omegalib);
410   strcat(Str3,"misle.dat");
411   fd = checkfopen(Str3,"rb");
412   site = cryptkey("misle.dat");
413   for(j=0;j<LENGTH;j++) {
414     for(i=0;i<WIDTH;i++) {
415       Level->site[i][j].lstatus = 0;
416       Level->site[i][j].roomnumber = RS_MAGIC_ISLE;
417       Level->site[i][j].p_locf = L_NO_OP;
418       site = getc(fd)^site;
419       switch(site) {
420       case 'E':
421 	Level->site[i][j].locchar = FLOOR;
422 	if (! empty)
423 	  make_site_monster(i,j,EATER); /* eater of magic */
424 	break;
425       case 'm':
426 	Level->site[i][j].locchar = FLOOR;
427 	if (! empty)
428 	  make_site_monster(i,j,MIL_PRIEST); /* militant priest */
429 	break;
430       case 'n':
431 	Level->site[i][j].locchar = FLOOR;
432 	if (! empty)
433 	  make_site_monster(i,j,NAZGUL);
434 	break;
435       case 'X':
436 	Level->site[i][j].locchar = FLOOR;
437 	Level->site[i][j].p_locf = L_TACTICAL_EXIT;
438 	break;
439       case '#':
440 	Level->site[i][j].locchar = WALL;
441 	Level->site[i][j].aux = 150;
442 	break;
443       case '4':
444 	Level->site[i][j].locchar = RUBBLE;
445 	Level->site[i][j].p_locf = L_RUBBLE;
446 	break;
447       case '~':
448 	Level->site[i][j].locchar = WATER;
449 	Level->site[i][j].p_locf = L_CHAOS;
450 	break;
451       case '=':
452 	Level->site[i][j].locchar = WATER;
453 	Level->site[i][j].p_locf = L_MAGIC_POOL;
454 	break;
455       case '-':
456 	Level->site[i][j].locchar = CLOSED_DOOR;
457 	break;
458       case '|':
459 	Level->site[i][j].locchar = OPEN_DOOR;
460 	break;
461       case '.':
462 	Level->site[i][j].locchar = FLOOR;
463 	break;
464       }
465     }
466     site = getc(fd)^site;
467   }
468   fclose(fd);
469 }
470 
471 
472 /* loads a temple into Level*/
load_temple(deity,populate)473 void load_temple(deity, populate)
474 int deity;
475 int populate;
476 {
477   int i,j;
478   char site;
479   pml ml;
480   FILE *fd;
481 
482   /* WDT HACK: I don't know why this is wrong.  Shrug.  David Givens
483    * suggested removing it, and he has more experience with Omega
484    * than I, so... */
485 /*  initrand(Current_Environment, deity); */ /* FIXED! 12/30/98 */
486   TempLevel = Level;
487   if (ok_to_free(TempLevel)) {
488 #ifndef SAVE_LEVELS
489     free_level(TempLevel);
490 #endif
491     TempLevel = NULL;
492   }
493 #ifndef SAVE_LEVELS
494   Level = ((plv) checkmalloc(sizeof(levtype)));
495 #else
496   msdos_changelevel(TempLevel,0,-1);
497   Level = &TheLevel;
498 #endif
499   clear_level(Level);
500   Level->environment = E_TEMPLE;
501   strcpy(Str3,Omegalib);
502   strcat(Str3,"temple.dat");
503   fd = checkfopen(Str3,"rb");
504   site = cryptkey("temple.dat");
505   for(j=0;j<LENGTH;j++) {
506     for(i=0;i<WIDTH;i++) {
507       switch(deity) {
508       case ODIN: Level->site[i][j].roomnumber = RS_ODIN; break;
509       case SET: Level->site[i][j].roomnumber = RS_SET; break;
510       case HECATE: Level->site[i][j].roomnumber = RS_HECATE; break;
511       case ATHENA: Level->site[i][j].roomnumber = RS_ATHENA; break;
512       case DRUID: Level->site[i][j].roomnumber = RS_DRUID; break;
513       case DESTINY: Level->site[i][j].roomnumber = RS_DESTINY; break;
514       }
515       site = getc(fd)^site;
516       switch(site) {
517       case '8':
518 	Level->site[i][j].locchar = ALTAR;
519 	Level->site[i][j].p_locf = L_ALTAR;
520 	Level->site[i][j].aux = deity;
521 	break;
522       case 'H':
523 	Level->site[i][j].locchar = FLOOR;
524 	if (populate && (!Player.patron ||
525 	    strcmp(Player.name,Priest[Player.patron]) ||
526 	    Player.rank[PRIESTHOOD] != HIGHPRIEST))
527 	  make_high_priest(i,j,deity);
528 	break;
529       case 'S':
530 	Level->site[i][j].locchar = FLOOR;
531 	if (!Player.patron ||
532 	    strcmp(Player.name,Priest[Player.patron]) ||
533 	    Player.rank[PRIESTHOOD] != HIGHPRIEST)
534 	  lset(i,j,SECRET);
535 	break;
536       case 'W':
537 	Level->site[i][j].locchar = FLOOR;
538 	if (deity != Player.patron && deity != DRUID)
539 	  Level->site[i][j].p_locf = L_TEMPLE_WARNING;
540 	break;
541       case 'm':
542 	Level->site[i][j].locchar = FLOOR;
543 	if (populate)
544 	  make_site_monster(i,j,MIL_PRIEST); /* militant priest */
545 	break;
546       case 'd':
547 	Level->site[i][j].locchar = FLOOR;
548 	if (populate)
549 	  make_site_monster(i,j,DOBERMAN); /* doberman death hound */
550 	break;
551       case 'X':
552 	Level->site[i][j].locchar = FLOOR;
553 	Level->site[i][j].p_locf = L_TACTICAL_EXIT;
554 	break;
555       case '#':
556 	if (deity != DRUID) {
557 	  Level->site[i][j].locchar = WALL;
558 	  Level->site[i][j].aux = 150;
559 	}
560 	else {
561 	  Level->site[i][j].locchar = HEDGE;
562 	  Level->site[i][j].p_locf = L_HEDGE;
563 	}
564 	break;
565       case '.':
566 	Level->site[i][j].locchar = FLOOR;
567 	break;
568       case 'x':
569 	Level->site[i][j].locchar = FLOOR;
570 	random_temple_site(i,j,deity,populate);
571 	break;
572       case '?':
573 	if (deity != DESTINY)
574 	  Level->site[i][j].locchar = FLOOR;
575 	else {
576 	  Level->site[i][j].locchar = ABYSS;
577 	  Level->site[i][j].p_locf = L_ADEPT;
578 	}
579 	break;
580       case '-':
581 	Level->site[i][j].locchar = CLOSED_DOOR;
582 	break;
583       case '|':
584 	Level->site[i][j].locchar = OPEN_DOOR;
585 	break;
586       }
587     }
588     site = getc(fd)^site;
589   }
590   /* Main Temple is peaceful for player of same sect,druids always peaceful. */
591   if ((Player.patron == deity) || (deity == DRUID))
592     for(ml=Level->mlist;ml!=NULL;ml=ml->next)
593       m_status_reset(ml->m,HOSTILE);
594   fclose(fd);
595 /*  initrand(-2, 0); */ /* FIXED! 12/30/98 */
596 }
597 
random_temple_site(i,j,deity,populate)598 void random_temple_site(i,j,deity,populate)
599 int i,j,deity,populate;
600 {
601   switch(random_range(12)) {
602   case 0:
603     if (populate)
604       make_site_monster(i,j,MEND_PRIEST);
605     break; /* mendicant priest */
606   case 1:
607     Level->site[i][j].locchar = WATER;
608     Level->site[i][j].p_locf = L_MAGIC_POOL;
609   case 2:
610     if (populate)
611       make_site_monster(i,j,INNER_DEMON);
612     break; /* inner circle demon */
613   case 3:
614     if (populate)
615       make_site_monster(i,j,ANGEL);
616     break; /* angel of apropriate sect */
617   case 4:
618     if (populate)
619       make_site_monster(i,j,HIGH_ANGEL);
620     break; /* high angel of apropriate sect */
621   case 5:
622     if (populate)
623       make_site_monster(i,j,ARCHANGEL);
624     break; /* archangel of apropriate sect */
625   }
626 }
627 
make_high_priest(i,j,deity)628 void make_high_priest(i,j,deity)
629 int i,j,deity;
630 {
631   pml ml = ((pml) checkmalloc(sizeof(mltype)));
632   pmt m = ((pmt) checkmalloc(sizeof(montype)));
633   make_hiscore_npc(m,deity);
634   m->x = i;
635   m->y = j;
636   Level->site[i][j].creature = m;
637   ml->m = m;
638   ml->next = Level->mlist;
639   Level->mlist = ml;
640 }
641