added worldarea -> will be responsible for world map rendering
[dboe.git] / fields.c
blobf0baaf649a69293e2035ccb15683a4b20485dd8b
1 #include <windows.h>
3 #include "global.h"
4 #include "locutils.h"
5 #include "fields.h"
7 extern current_town_type far c_town;
8 extern short overall_mode,which_combat_type,current_pc,town_type;
9 extern Boolean web,crate,barrel,fire_barrier,force_barrier,quickfire,force_wall,fire_wall,antimagic,scloud,ice_wall,blade_wall;
10 extern Boolean sleep_field;
11 extern big_tr_type far t_d;
12 extern outdoor_record_type far outdoors[2][2];
13 extern unsigned char far combat_terrain[64][64];
14 extern unsigned char far out[96][96];
15 extern unsigned char far out_e[96][96];
16 extern unsigned char far misc_i[64][64];
17 extern unsigned char far sfx[64][64];
18 extern char terrain_blocked[256];
19 extern short town_size[3];
20 extern scenario_data_type far scenario;
22 Boolean is_explored(short i,short j)
24 if (is_out()) {
25 if ((i != minmax(0,95,i)) || (j != minmax(0,95,j)))
26 return FALSE;
27 return (out_e[i][j] != 0) ? TRUE : FALSE;
29 if (c_town.explored[i][j] & 1) {
30 return TRUE;
32 else return FALSE;
34 void make_explored(short i,short j)
36 if (is_out())
37 out_e[i][j] = 1;
38 c_town.explored[i][j] = c_town.explored[i][j] | 1;
41 void take_explored(short i,short j)
43 if (is_out())
44 out_e[i][j] = 0;
45 c_town.explored[i][j] = c_town.explored[i][j] & 254;
48 Boolean is_out()
50 if ((overall_mode == 0) || (overall_mode == 35))
51 return TRUE;
52 else return FALSE;
54 Boolean is_town()
56 if (((overall_mode > 0) && (overall_mode < 10)) || (overall_mode == 36))
57 return TRUE;
58 else return FALSE;
60 Boolean is_combat()
62 if (((overall_mode >= 10) && (overall_mode < 20)) || (overall_mode == 37))
63 return TRUE;
64 else return FALSE;
69 Boolean special(short i,short j)
70 /**/{
71 if (((misc_i[i][j]) & 2) != 0)
72 return TRUE;
73 else return FALSE;
75 void flip_special(short i,short j)
76 /**/{
77 misc_i[i][j] = misc_i[i][j] ^ (char) (2);
79 void make_special(short i,short j)
80 /**/{
81 misc_i[i][j] = misc_i[i][j] | (char) (2);
83 void take_special(short i,short j)
84 /**/{
85 misc_i[i][j] = misc_i[i][j] & 253;
88 Boolean is_web(short i,short j)
89 /**/{
90 return (misc_i[i][j] & 4) ? TRUE : FALSE;
92 void make_web(short i,short j)
93 /**/{
94 if (spot_impassable(i,j) == TRUE)
95 return;
96 if ((misc_i[i][j] & 224) || (c_town.explored[i][j] & 238))
97 return;
98 misc_i[i][j] = misc_i[i][j] | 4;
99 web = TRUE;
101 void take_web(short i,short j)
102 /**/{
103 misc_i[i][j] = misc_i[i][j] & 251;
106 Boolean is_crate(short i,short j)
107 /**/{
108 return (misc_i[i][j] & 8) ? TRUE : FALSE;
110 void make_crate(short i,short j)
111 /**/{
112 // if (misc_i[i][j] & 240)
113 // return;
114 misc_i[i][j] = misc_i[i][j] | 8;
115 crate = TRUE;
117 void take_crate(short i,short j)
118 /**/{
119 misc_i[i][j] = misc_i[i][j] & 247;
122 Boolean is_barrel(short i,short j)
123 /**/{
124 return (misc_i[i][j] & 16) ? TRUE : FALSE;
126 void make_barrel(short i,short j)
127 /**/{
128 // if (misc_i[i][j] & 234)
129 // return;
130 misc_i[i][j] = misc_i[i][j] | 16;
131 barrel = TRUE;
133 void take_barrel(short i,short j)
134 /**/{
135 misc_i[i][j] = misc_i[i][j] & 239;
138 Boolean is_fire_barrier(short i,short j)
139 /**/{
140 return (misc_i[i][j] & 32) ? TRUE : FALSE;
142 void make_fire_barrier(short i,short j)
143 /**/{
144 if ((is_antimagic(i,j)) && (get_ran(1,0,3) < 3))
145 return;
146 if (misc_i[i][j] & 248)
147 return;
148 take_web(i,j);
149 c_town.explored[i][j] = c_town.explored[i][j] & 1;
150 misc_i[i][j] = misc_i[i][j] | 32;
151 fire_barrier = TRUE;
153 void take_fire_barrier(short i,short j)
154 /**/{
155 misc_i[i][j] = misc_i[i][j] & 223;
158 Boolean is_force_barrier(short i,short j)
159 /**/{
160 return (misc_i[i][j] & 64) ? TRUE : FALSE;
162 void make_force_barrier(short i,short j)
163 /**/{
164 if ((is_antimagic(i,j)) && (get_ran(1,0,2) < 2))
165 return;
166 if (misc_i[i][j] & 248)
167 return;
168 take_web(i,j);
169 c_town.explored[i][j] = c_town.explored[i][j] & 1;
170 misc_i[i][j] = misc_i[i][j] | 64;
171 force_barrier = TRUE;
173 void take_force_barrier(short i,short j)
174 /**/{
175 misc_i[i][j] = misc_i[i][j] & 191;
178 Boolean is_quickfire(short i,short j)
179 /**/{
180 return (misc_i[i][j] & 128) ? TRUE : FALSE;
182 void make_quickfire(short i,short j)
183 /**/{
184 unsigned char ter;
186 if ((is_antimagic(i,j)) && (get_ran(1,0,1) == 0))
187 return;
188 if ((is_force_barrier(i,j)) || (is_fire_barrier(i,j)))
189 return;
190 ter = coord_to_ter(i,j);
191 if (scenario.ter_types[ter].blockage == 1)
192 return;
193 if (scenario.ter_types[ter].blockage == 5)
194 return;
195 c_town.explored[i][j] = c_town.explored[i][j] & 1;
196 misc_i[i][j] = misc_i[i][j] & 3;
197 misc_i[i][j] = misc_i[i][j] | 128;
198 quickfire = TRUE;
200 void take_quickfire(short i,short j)
201 /**/{
202 misc_i[i][j] = misc_i[i][j] & 127;
205 Boolean is_force_wall(short i,short j)
206 /**/{
207 return (c_town.explored[i][j] & 2) ? TRUE : FALSE;
209 void make_force_wall(short i,short j)
210 /**/{
211 if (spot_impassable(i,j) == TRUE)
212 return;
213 if ((c_town.explored[i][j] & 74) || (misc_i[i][j] & 248))
214 return;
215 take_web(i,j);
216 take_fire_wall(i,j);
217 c_town.explored[i][j] = c_town.explored[i][j] | 2;
218 force_wall = TRUE;
220 void take_force_wall(short i,short j)
221 /**/{
222 c_town.explored[i][j] = c_town.explored[i][j] & 253;
226 Boolean is_fire_wall(short i,short j)
227 /**/{
228 return (c_town.explored[i][j] & 4) ? TRUE : FALSE;
230 void make_fire_wall(short i,short j)
231 /**/{
232 if (spot_impassable(i,j) == TRUE)
233 return;
234 if ((c_town.explored[i][j] & 248) || (misc_i[i][j] & 254))
235 return;
236 take_web(i,j);
237 c_town.explored[i][j] = c_town.explored[i][j] | 4;
238 fire_wall = TRUE;
240 void take_fire_wall(short i,short j)
241 /**/{
242 c_town.explored[i][j] = c_town.explored[i][j] & 251;
245 Boolean is_antimagic(short i,short j)
246 /**/{
247 return (c_town.explored[i][j] & 8) ? TRUE : FALSE;
249 void make_antimagic(short i,short j)
250 /**/{
251 if (spot_impassable(i,j) == TRUE)
252 return;
253 if (misc_i[i][j] & 224)
254 return;
256 c_town.explored[i][j] = c_town.explored[i][j] & 1;
257 c_town.explored[i][j] = c_town.explored[i][j] | 8;
258 antimagic = TRUE;
260 void take_antimagic(short i,short j)
261 /**/{
262 c_town.explored[i][j] = c_town.explored[i][j] & 247;
265 Boolean is_scloud(short i,short j)
266 /**/{
267 return (c_town.explored[i][j] & 16) ? TRUE : FALSE;
269 void make_scloud(short i,short j)
270 /**/{
271 if (spot_impassable(i,j) == TRUE)
272 return;
274 if ((c_town.explored[i][j] & 238) || (misc_i[i][j] & 224))
275 return;
276 c_town.explored[i][j] = c_town.explored[i][j] | 16;
277 scloud = TRUE;
279 void take_scloud(short i,short j)
280 /**/{
281 c_town.explored[i][j] = c_town.explored[i][j] & 239;
284 Boolean is_ice_wall(short i,short j)
285 /**/{
286 return (c_town.explored[i][j] & 32) ? TRUE : FALSE;
288 void make_ice_wall(short i,short j)
289 /**/{
290 if (spot_impassable(i,j) == TRUE)
291 return;
292 if ((c_town.explored[i][j] & 74) || (misc_i[i][j] & 252))
293 return;
294 take_fire_wall(i,j);
295 take_scloud(i,j);
296 c_town.explored[i][j] = c_town.explored[i][j] | 32;
297 ice_wall = TRUE;
299 void take_ice_wall(short i,short j)
300 /**/{
301 c_town.explored[i][j] = c_town.explored[i][j] & 223;
305 Boolean is_blade_wall(short i,short j)
306 /**/{
307 return (c_town.explored[i][j] & 64) ? TRUE : FALSE;
309 void make_blade_wall(short i,short j)
310 /**/{
311 if (spot_impassable(i,j) == TRUE)
312 return;
313 if ((c_town.explored[i][j] & 8) || (misc_i[i][j] & 224))
314 return;
315 c_town.explored[i][j] = c_town.explored[i][j] & 9;
316 c_town.explored[i][j] = c_town.explored[i][j] | 64;
317 blade_wall = TRUE;
319 void take_blade_wall(short i,short j)
320 /**/{
321 c_town.explored[i][j] = c_town.explored[i][j] & 191;
323 Boolean is_sleep_cloud(short i,short j)
324 /**/{
325 return (c_town.explored[i][j] & 128) ? TRUE : FALSE;
327 void make_sleep_cloud(short i,short j)
328 /**/{
329 if (spot_impassable(i,j) == TRUE)
330 return;
331 if ((c_town.explored[i][j] & 8) || (misc_i[i][j] & 224))
332 return;
333 c_town.explored[i][j] = c_town.explored[i][j] & 9;
334 c_town.explored[i][j] = c_town.explored[i][j] | 128;
335 sleep_field = TRUE;
337 void take_sleep_cloud(short i,short j)
338 /**/{
339 c_town.explored[i][j] = c_town.explored[i][j] & 127;
342 // START SFX
343 Boolean is_small_blood(short i,short j)
345 return (sfx[i][j] & 1) ? TRUE : FALSE;
347 Boolean is_medium_blood(short i,short j)
349 return (sfx[i][j] & 2) ? TRUE : FALSE;
351 Boolean is_large_blood(short i,short j)
353 return (sfx[i][j] & 4) ? TRUE : FALSE;
355 Boolean is_small_slime(short i,short j)
357 return (sfx[i][j] & 8) ? TRUE : FALSE;
359 Boolean is_big_slime(short i,short j)
361 return (sfx[i][j] & 16) ? TRUE : FALSE;
363 Boolean is_ash(short i,short j)
365 return (sfx[i][j] & 32) ? TRUE : FALSE;
367 Boolean is_bones(short i,short j)
369 return (sfx[i][j] & 64) ? TRUE : FALSE;
371 Boolean is_rubble(short i,short j)
373 return (sfx[i][j] & 128) ? TRUE : FALSE;
375 void make_sfx(short i,short j, short type)
377 unsigned char ter;
379 if (get_obscurity(i,j) > 0)
380 return;
381 ter = coord_to_ter(i,j);
382 if (terrain_blocked[ter] != 0)
383 return;
384 switch (type) {
385 case 1: case 2:
386 if (sfx[i][j] == 4)
387 return;
388 if (sfx[i][j] < 4)
389 type = min(3,type + sfx[i][j]);
390 break;
391 case 4:
392 if (sfx[i][j] == 8)
393 type = 5;
394 break;
396 sfx[i][j] = s_pow(2,type - 1);
399 void spread_sfx(short type,short prob)
400 // prob is 1 - 100
402 short i,j;
404 for (i = 0; i < town_size[town_type]; i++)
405 for (j = 0; j < town_size[town_type]; j++)
406 if ((t_d.terrain[i][j] < 5) && (get_ran(1,0,100) <= prob))
407 make_sfx(i,j,type);