1 /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
2 /* village.c */
3 /* some functions to make the village levels */
4
5 #include "glob.h"
6
7
8 /* loads the village level into Level*/
load_village(villagenum,populate)9 void load_village(villagenum, populate)
10 int villagenum;
11 int populate;
12 {
13 int i,j;
14 char site;
15
16 FILE *fd;
17
18
19 TempLevel = Level;
20 if (ok_to_free(TempLevel)) {
21 #ifndef SAVE_LEVELS
22 free_level(TempLevel);
23 #endif
24 TempLevel = NULL;
25 }
26
27 initrand(Current_Environment, villagenum);
28
29 assign_village_function(0,0,TRUE);
30
31 #ifndef SAVE_LEVELS
32 Level = ((plv) checkmalloc(sizeof(levtype)));
33 #else
34 msdos_changelevel(TempLevel,0,-1);
35 Level = &TheLevel;
36 #endif
37 clear_level(Level);
38 Level->environment = E_VILLAGE;
39 strcpy(Str3,Omegalib);
40 switch(villagenum) {
41 case 1:strcat(Str3,"village1.dat");break;
42 case 2:strcat(Str3,"village2.dat");break;
43 case 3:strcat(Str3,"village3.dat");break;
44 case 4:strcat(Str3,"village4.dat");break;
45 case 5:strcat(Str3,"village5.dat");break;
46 case 6:strcat(Str3,"village6.dat");break;
47 }
48 site = cryptkey("village.dat");
49 fd = checkfopen(Str3,"rb");
50 for(j=0;j<LENGTH;j++) {
51 for(i=0;i<WIDTH;i++) {
52 lset(i,j,SEEN);
53 site = getc(fd)^site;
54 Level->site[i][j].p_locf = L_NO_OP;
55 switch(site) {
56 case 'f':
57 Level->site[i][j].locchar = FLOOR;
58 if (populate)
59 make_food_bin(i,j);
60 break;
61 case 'g':
62 Level->site[i][j].locchar = FLOOR;
63 Level->site[i][j].p_locf = L_GRANARY;
64 break;
65 case 'h':
66 Level->site[i][j].locchar = FLOOR;
67 if (populate)
68 make_horse(i,j);
69 break;
70 case 'S':
71 Level->site[i][j].locchar = FLOOR;
72 Level->site[i][j].p_locf = L_STABLES;
73 break;
74 case 'H':
75 Level->site[i][j].locchar = FLOOR;
76 if (populate)
77 make_merchant(i,j);
78 break;
79 case 'C':
80 Level->site[i][j].locchar = FLOOR;
81 Level->site[i][j].p_locf = L_COMMONS;
82 break;
83 case 's':
84 Level->site[i][j].locchar = FLOOR;
85 if (populate)
86 make_sheep(i,j);
87 break;
88 case 'x':
89 assign_village_function(i,j,FALSE);
90 break;
91 case 'X':
92 Level->site[i][j].locchar = FLOOR;
93 Level->site[i][j].p_locf = L_COUNTRYSIDE;
94 break;
95 case 'G':
96 Level->site[i][j].locchar = FLOOR;
97 if (populate) {
98 make_guard(i,j);
99 Level->site[i][j].creature->aux1 = i;
100 Level->site[i][j].creature->aux2 = j;
101 }
102 break;
103 case '^':
104 Level->site[i][j].locchar = FLOOR;
105 Level->site[i][j].p_locf = L_TRAP_SIREN;
106 break;
107 case '"':
108 Level->site[i][j].locchar = HEDGE;
109 Level->site[i][j].p_locf = L_HEDGE;
110 break;
111 case '~':
112 Level->site[i][j].locchar = WATER;
113 Level->site[i][j].p_locf = L_WATER;
114 break;
115 case '+':
116 Level->site[i][j].locchar = WATER;
117 Level->site[i][j].p_locf = L_CHAOS;
118 break;
119 case '\'':
120 Level->site[i][j].locchar = HEDGE;
121 Level->site[i][j].p_locf = L_TRIFID;
122 break;
123 case '!':
124 special_village_site(i,j,villagenum);
125 break;
126 case '#':
127 Level->site[i][j].locchar = WALL;
128 Level->site[i][j].aux = 100;
129 break;
130 case '.':
131 Level->site[i][j].locchar = FLOOR;
132 break;
133 case '-':
134 Level->site[i][j].locchar = CLOSED_DOOR;
135 break;
136 case '1':
137 Level->site[i][j].locchar = STATUE;
138 break;
139 }
140 if (loc_statusp(i,j,SECRET))
141 Level->site[i][j].showchar = WALL;
142 else Level->site[i][j].showchar = Level->site[i][j].locchar;
143 }
144 site = getc(fd)^site;
145 }
146 fclose(fd);
147 initrand(E_RESTORE, 0);
148 }
149
make_guard(i,j)150 void make_guard(i,j)
151 int i,j;
152 {
153 pml tml = ((pml) (checkmalloc(sizeof(mltype))));
154 tml->m = (Level->site[i][j].creature = make_creature(GUARD));
155 tml->m->x = i;
156 tml->m->y = j;
157 tml->next = Level->mlist;
158 Level->mlist = tml;
159 }
160
make_sheep(i,j)161 void make_sheep(i,j)
162 int i,j;
163 {
164 pml tml = ((pml) (checkmalloc(sizeof(mltype))));
165 tml->m = (Level->site[i][j].creature = make_creature(SHEEP));
166 tml->m->x = i;
167 tml->m->y = j;
168 tml->next = Level->mlist;
169 Level->mlist = tml;
170 }
171
make_food_bin(i,j)172 void make_food_bin(i,j)
173 int i,j;
174 {
175 pol tol;
176 int k;
177
178 for(k=0;k<10;k++) {
179 tol = ((pol) checkmalloc(sizeof(oltype)));
180 tol->thing = ((pob) checkmalloc(sizeof(objtype)));
181 make_food(tol->thing,15); /* grain */
182 tol->next = Level->site[i][j].things;
183 Level->site[i][j].things = tol;
184 }
185 }
186
make_horse(i,j)187 void make_horse(i,j)
188 int i,j;
189 {
190 pml tml = ((pml) (checkmalloc(sizeof(mltype))));
191 tml->m = (Level->site[i][j].creature = make_creature(HORSE));
192 tml->m->x = i;
193 tml->m->y = j;
194 tml->next = Level->mlist;
195 Level->mlist = tml;
196 }
197
198
make_merchant(i,j)199 void make_merchant(i,j)
200 int i,j;
201 {
202 pml tml = ((pml) (checkmalloc(sizeof(mltype))));
203 tml->m = (Level->site[i][j].creature = make_creature(MERCHANT));
204 tml->m->x = i;
205 tml->m->y = j;
206 tml->next = Level->mlist;
207 Level->mlist = tml;
208 }
209
210
assign_village_function(x,y,setup)211 void assign_village_function(x,y,setup)
212 int x,y,setup;
213 {
214 static int next=0;
215 static int permutation[24]; /* number of x's in village map */
216 int i,j,k;
217
218
219 if (setup) {
220 next = 0;
221 for(i=0;i<24;i++)
222 permutation[i] = i;
223 for(i=0;i<24;i++) {
224 j = permutation[i];
225 k = random_range(24);
226 permutation[i] = permutation[k];
227 permutation[k] = j;
228 }
229 }
230 else {
231
232 lset(x,y+1,STOPS);
233 lset(x+1,y,STOPS);
234 lset(x-1,y,STOPS);
235 lset(x,y-1,STOPS);
236 lset(x,y,STOPS);
237
238
239 switch(permutation[next++]) {
240 case 0:
241 Level->site[x][y].locchar = OPEN_DOOR;
242 Level->site[x][y].p_locf = L_ARMORER;
243 break;
244 case 1:
245 Level->site[x][y].locchar = OPEN_DOOR;
246 Level->site[x][y].p_locf = L_HEALER;
247 break;
248 case 2:
249 Level->site[x][y].locchar = OPEN_DOOR;
250 Level->site[x][y].p_locf = L_TAVERN;
251 break;
252 case 3:
253 Level->site[x][y].locchar = OPEN_DOOR;
254 Level->site[x][y].p_locf = L_COMMANDANT;
255 break;
256 case 4:
257 Level->site[x][y].locchar = OPEN_DOOR;
258 Level->site[x][y].p_locf = L_CARTOGRAPHER;
259 break;
260 default:
261 Level->site[x][y].locchar = CLOSED_DOOR;
262 if (random_range(2))
263 Level->site[x][y].aux = LOCKED;
264 if (random_range(2))
265 Level->site[x][y].p_locf = L_HOVEL;
266 else Level->site[x][y].p_locf = L_HOUSE;
267 break;
268 }
269 }
270 }
271
272
special_village_site(i,j,villagenum)273 void special_village_site(i,j,villagenum)
274 int i,j,villagenum;
275 {
276 if (villagenum == 1) {
277 Level->site[i][j].locchar = ALTAR;
278 Level->site[i][j].p_locf = L_LAWSTONE;
279 }
280 if (villagenum == 2) {
281 Level->site[i][j].locchar = ALTAR;
282 Level->site[i][j].p_locf = L_BALANCESTONE;
283 }
284 else if (villagenum == 3) {
285 Level->site[i][j].locchar = ALTAR;
286 Level->site[i][j].p_locf = L_CHAOSTONE;
287 }
288 else if (villagenum == 4) {
289 Level->site[i][j].locchar = ALTAR;
290 Level->site[i][j].p_locf = L_MINDSTONE;
291 }
292 else if (villagenum == 5) {
293 Level->site[i][j].locchar = ALTAR;
294 Level->site[i][j].p_locf = L_SACRIFICESTONE;
295 }
296 else if (villagenum == 6) {
297 Level->site[i][j].locchar = ALTAR;
298 Level->site[i][j].p_locf = L_VOIDSTONE;
299 }
300 }
301