1 /* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
2 /* env.c */
3 /* some load_* routines for special environments */
4 
5 #include "glob.h"
6 
7 /* loads the arena level into Level*/
load_arena()8 void load_arena()
9 {
10   int i,j;
11   char site;
12   pob box=((pob)checkmalloc(sizeof(objtype)));
13   FILE *fd;
14 
15   *box = Objects[THINGID+0];
16 
17   TempLevel = Level;
18   if (ok_to_free(TempLevel)) {
19 #ifndef SAVE_LEVELS
20     free_level(TempLevel);
21 #endif
22     TempLevel = NULL;
23   }
24 #ifndef SAVE_LEVELS
25   Level = ((plv) checkmalloc(sizeof(levtype)));
26 #else
27   msdos_changelevel(TempLevel,0,-1);
28   Level = &TheLevel;
29 #endif
30   clear_level(Level);
31   Level->environment = E_ARENA;
32   strcpy(Str3,Omegalib);
33   strcat(Str3,"arena.dat");
34   fd = checkfopen(Str3,"rb");
35   site = cryptkey("arena.dat");
36   for(j=0;j<LENGTH;j++) {
37     for(i=0;i<WIDTH;i++) {
38       Level->site[i][j].lstatus = SEEN+LIT;
39       Level->site[i][j].roomnumber = RS_ARENA;
40       site = getc(fd)^site;
41       Level->site[i][j].p_locf = L_NO_OP;
42       switch(site) {
43       case 'P':
44 	Level->site[i][j].locchar = PORTCULLIS;
45 	Level->site[i][j].p_locf = L_PORTCULLIS;
46 	break;
47       case 'X':
48 	Level->site[i][j].locchar = FLOOR;
49 	Level->site[i][j].p_locf = L_ARENA_EXIT;
50 	break;
51       case '#':
52 	Level->site[i][j].locchar = WALL;
53 	break;
54       case '.':
55 	Level->site[i][j].locchar = FLOOR;
56 	break;
57       }
58       Level->site[i][j].showchar = Level->site[i][j].locchar;
59     }
60     site = getc(fd)^site;
61   }
62   fclose(fd);
63   Level->site[60][7].creature = Arena_Monster;
64   Arena_Monster->x = 60;
65   Arena_Monster->y = 7;
66   Arena_Monster->sense = 50;
67   m_pickup(Arena_Monster,box);
68   m_status_set(Arena_Monster,AWAKE);
69   Level->mlist = (pml) checkmalloc(sizeof(mltype));
70   Level->mlist->m = Arena_Monster;
71   Level->mlist->next = NULL;
72   /* hehehehe cackled the dungeon master.... */
73   print2("Your opponent holds the only way you can leave!");
74   Arena_Monster->hp += Arena_Monster->level*10;
75   Arena_Monster->hit += Arena_Monster->hit;
76   Arena_Monster->dmg += Arena_Monster->dmg/2;
77 }
78 
79 /* loads the sorcereror's circle into Level*/
load_circle(populate)80 void load_circle(populate)
81 int populate;
82 {
83   int i,j;
84   int safe = (Player.rank[CIRCLE] > 0);
85   char site;
86   FILE *fd;
87 
88   TempLevel = Level;
89   if (ok_to_free(TempLevel)) {
90 #ifndef SAVE_LEVELS
91     free_level(TempLevel);
92 #endif
93     TempLevel = NULL;
94   }
95 #ifndef SAVE_LEVELS
96   Level = ((plv) checkmalloc(sizeof(levtype)));
97 #else
98   msdos_changelevel(TempLevel,0,-1);
99   Level = &TheLevel;
100 #endif
101   clear_level(Level);
102   Level->environment = E_CIRCLE;
103   strcpy(Str3,Omegalib);
104   strcat(Str3,"circle.dat");
105   fd = checkfopen(Str3,"rb");
106   site = cryptkey("circle.dat");
107   for(j=0;j<LENGTH;j++) {
108     for(i=0;i<WIDTH;i++) {
109       Level->site[i][j].lstatus = 0;
110       Level->site[i][j].roomnumber = RS_CIRCLE;
111       Level->site[i][j].p_locf = L_NO_OP;
112       site = getc(fd)^site;
113       switch(site) {
114       case 'P':
115 	Level->site[i][j].locchar = FLOOR;
116 	if (populate) {
117 	  make_prime(i,j); /* prime sorceror */
118 	  Level->site[i][j].creature->specialf = M_SP_PRIME;
119 	  if (! safe) m_status_set(Level->site[i][j].creature,HOSTILE);
120 	}
121 	break;
122       case 'D':
123 	Level->site[i][j].locchar = FLOOR;
124 	if (populate) {
125 	  make_site_monster(i,j,DEMON_PRINCE); /* prime circle demon */
126 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
127 	  Level->site[i][j].creature->specialf = M_SP_COURT;
128 	}
129 	break;
130       case 's':
131 	Level->site[i][j].locchar = FLOOR;
132 	if (populate) {
133 	  make_site_monster(i,j,SERV_CHAOS); /* servant of chaos */
134 	  Level->site[i][j].creature->specialf = M_SP_COURT;
135 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
136 	}
137 	break;
138       case 'e':
139 	Level->site[i][j].locchar = FLOOR;
140 	if (populate) {
141 	  make_site_monster(i,j,ENCHANTOR); /* enchanter */
142 	  Level->site[i][j].creature->specialf = M_SP_COURT;
143 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
144 	}
145 	break;
146       case 'n':
147 	Level->site[i][j].locchar = FLOOR;
148 	if (populate) {
149 	  make_site_monster(i,j,NECROMANCER); /* necromancer */
150 	  Level->site[i][j].creature->specialf = M_SP_COURT;
151 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
152 	}
153 	break;
154       case 'T':
155 	Level->site[i][j].locchar = FLOOR;
156 	if (populate) {
157 	  make_site_monster(i,j,THAUMATURGIST); /* High Thaumaturgist */
158 	  Level->site[i][j].creature->specialf = M_SP_COURT;
159 	  if (safe) m_status_reset(Level->site[i][j].creature,HOSTILE);
160 	}
161 	break;
162       case '#':
163 	Level->site[i][j].locchar = WALL;
164 	Level->site[i][j].aux = 1000;
165 	break;
166       case 'L':
167 	Level->site[i][j].locchar = FLOOR;
168 	Level->site[i][j].p_locf = L_CIRCLE_LIBRARY;
169 	break;
170       case '?':
171 	Level->site[i][j].locchar = FLOOR;
172 	Level->site[i][j].p_locf = L_TOME1;
173 	break;
174       case '!':
175 	Level->site[i][j].locchar = FLOOR;
176 	Level->site[i][j].p_locf = L_TOME2;
177 	break;
178       case 'S':
179 	Level->site[i][j].locchar = FLOOR;
180 	lset(i,j,SECRET);
181 	break;
182       case '.':
183 	Level->site[i][j].locchar = FLOOR;
184 	break;
185       case '-':
186 	Level->site[i][j].locchar = CLOSED_DOOR;
187 	break;
188       }
189     }
190     site = getc(fd)^site;
191   }
192   fclose(fd);
193 }
194 
195 /* make the prime sorceror */
make_prime(i,j)196 void make_prime(i,j)
197 int i,j;
198 {
199   pml ml = ((pml) checkmalloc(sizeof(mltype)));
200   pmt m = ((pmt) checkmalloc(sizeof(montype)));
201   pol ol;
202   pob o;
203   make_hiscore_npc(m,10); /* 10 is index for prime */
204   m->x = i;
205   m->y = j;
206   Level->site[i][j].creature = m;
207   ml->m = m;
208   ml->next = Level->mlist;
209   Level->mlist = ml;
210 
211   if (Objects[ARTIFACTID+21].uniqueness != UNIQUE_TAKEN) {
212     ol  = ((pol) checkmalloc(sizeof(oltype)));
213     o  = ((pob) checkmalloc(sizeof(objtype)));
214     *o = Objects[ARTIFACTID+21];
215     ol->thing = o;
216     ol->next = NULL;
217     m->possessions = ol;
218   }
219 }
220 
221 
222 
223 
224 
225 
226 /* loads the court of the archmage into Level*/
load_court(populate)227 void load_court(populate)
228 int populate;
229 {
230   int i,j;
231   char site;
232   FILE *fd;
233 
234   TempLevel = Level;
235   if (ok_to_free(TempLevel)) {
236 #ifndef SAVE_LEVELS
237     free_level(TempLevel);
238 #endif
239     TempLevel = NULL;
240   }
241 #ifndef SAVE_LEVELS
242   Level = ((plv) checkmalloc(sizeof(levtype)));
243 #else
244   msdos_changelevel(TempLevel,0,-1);
245   Level = &TheLevel;
246 #endif
247   clear_level(Level);
248   Level->environment = E_COURT;
249   strcpy(Str3,Omegalib);
250   strcat(Str3,"court.dat");
251   fd = checkfopen(Str3,"rb");
252   site = cryptkey("court.dat");
253   for(j=0;j<LENGTH;j++) {
254     for(i=0;i<WIDTH;i++) {
255       Level->site[i][j].lstatus = 0;
256       Level->site[i][j].roomnumber = RS_COURT;
257       Level->site[i][j].p_locf = L_NO_OP;
258       site = getc(fd)^site;
259       switch(site) {
260       case '5':
261 	Level->site[i][j].locchar = CHAIR;
262 	Level->site[i][j].p_locf = L_THRONE;
263 	if (populate) {
264 	  make_specific_treasure(i,j,ARTIFACTID+22);
265 	  make_archmage(i,j);
266 	  m_status_reset(Level->site[i][j].creature,HOSTILE);
267 	  m_status_reset(Level->site[i][j].creature,MOBILE);
268 	}
269 	break;
270       case 'e':
271 	Level->site[i][j].locchar = FLOOR;
272 	if (populate) {
273 	  make_site_monster(i,j,ENCHANTOR); /* enchanter */
274 	  m_status_reset(Level->site[i][j].creature,HOSTILE);
275 	  Level->site[i][j].creature->specialf = M_SP_COURT;
276 	}
277 	break;
278       case 'n':
279 	Level->site[i][j].locchar = FLOOR;
280 	if (populate) {
281 	  make_site_monster(i,j,NECROMANCER); /* necromancer */
282 	  m_status_reset(Level->site[i][j].creature,HOSTILE);
283 	  Level->site[i][j].creature->specialf = M_SP_COURT;
284 	}
285 	break;
286       case 'T':
287 	Level->site[i][j].locchar = FLOOR;
288 	if (populate) {
289 	  make_site_monster(i,j,THAUMATURGIST); /* High Thaumaturgist */
290 	  m_status_reset(Level->site[i][j].creature,HOSTILE);
291 	  Level->site[i][j].creature->specialf = M_SP_COURT;
292 	}
293 	break;
294       case '#':
295 	Level->site[i][j].locchar = WALL;
296 	Level->site[i][j].aux = 1000;
297 	break;
298       case 'G':
299 	Level->site[i][j].locchar = FLOOR;
300 	Level->site[i][j].locchar = FLOOR;
301 	if (populate) {
302 	  make_site_monster(i,j,GUARD); /* guard */
303 	  m_status_reset(Level->site[i][j].creature,HOSTILE);
304 	}
305 	break;
306       case '<':
307 	Level->site[i][j].locchar = STAIRS_UP;
308 	Level->site[i][j].p_locf = L_ESCALATOR;
309 	break;
310       case '.':
311 	Level->site[i][j].locchar = FLOOR;
312 	break;
313       }
314     }
315     site = getc(fd)^site;
316   }
317   fclose(fd);
318 }
319 
320 
321 
322 /* make the archmage */
make_archmage(i,j)323 void make_archmage(i,j)
324 int i,j;
325 {
326   pml ml = ((pml) checkmalloc(sizeof(mltype)));
327   pmt m = ((pmt) checkmalloc(sizeof(montype)));
328   make_hiscore_npc(m,9); /* 9 is index for archmage */
329   m->x = i;
330   m->y = j;
331   Level->site[i][j].creature = m;
332   ml->m = m;
333   ml->next = Level->mlist;
334   Level->mlist = ml;
335   m->specialf = M_SP_COURT;
336 }
337 
338