1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 // Filename    : OGENHILL.CPP
22 // Description : Generate hill
23 // Ownership   : Gilbert
24 
25 #include <ALL.h>
26 #include <OWORLD.h>
27 #include <OMATRIX.h>
28 #include <OHILLRES.h>
29 #include <OTERRAIN.h>
30 
31 
32 // ---------- begin of function World::gen_hills --------//
gen_hills(int terrainType)33 void World::gen_hills(int terrainType)
34 {
35 	// ------- scan each tile for an above-hill terrain tile -----//
36 	int x, y=0;
37 	char priTerrain, secTerrain, lowTerrain, highTerrain;
38 	char patternId;
39 	Location *aboveLoc, *locPtr;
40 	TerrainInfo *terrainInfo;
41 
42 	for(y = 0; y < max_y_loc; ++y)
43 	{
44 		x = 0;
45 		if( y > 0)
46 			aboveLoc = get_loc(x, y-1);
47 		else
48 			aboveLoc = NULL;
49 		locPtr = get_loc(x,y);
50 		for( ; x < max_x_loc; ++x, ++locPtr, ++aboveLoc)
51 		{
52 			terrainInfo = terrain_res[locPtr->terrain_id];
53 			priTerrain = terrainInfo->average_type;
54 			secTerrain = terrainInfo->secondary_type;
55 			highTerrain = (priTerrain >= secTerrain ? priTerrain : secTerrain);
56 			lowTerrain = (priTerrain >= secTerrain ? secTerrain : priTerrain);
57 			if( highTerrain >= terrainType)
58 			{
59 				// BUGHERE : ignore special or extra flag
60 				patternId = terrainInfo->pattern_id;
61 				if( lowTerrain >= terrainType)
62 				{
63 					// move this terrain one square north
64 					if( y > 0)
65 					{
66 						*aboveLoc = *locPtr;
67 
68 						// if y is max_y_loc-1, aboveLoc and locPtr looks the same
69 						// BUGHERE : repeat the same pattern below is a bug if patternId is not 0,9,10,13,14
70 						if( y == max_y_loc -1)
71 							locPtr->terrain_id = terrain_res.scan(priTerrain, secTerrain, patternId);
72 					}
73 				}
74 				else
75 				{
76 					short hillId = hill_res.scan(patternId, LOW_HILL_PRIORITY,0,0);
77 					err_when( !hillId );
78 					locPtr->set_hill(hillId);
79 					locPtr->set_fire_src(-100);
80 					//### begin alex 24/6 ###//
81 					locPtr->set_power_off();
82 					set_surr_power_off(x, y);
83 					//#### end alex 24/6 ####//
84 					if( y > 0)
85 					{
86 						aboveLoc->set_hill(hill_res.locate(patternId,
87 							hill_res[hillId]->sub_pattern_id, HIGH_HILL_PRIORITY,0));
88 						aboveLoc->set_fire_src(-100);
89 						//### begin alex 24/6 ###//
90 						aboveLoc->set_power_off();
91 						set_surr_power_off(x, y-1);
92 						//#### end alex 24/6 ####//
93 					}
94 					// set terrain type to pure teraType-1
95 					locPtr->terrain_id = terrain_res.scan(lowTerrain, lowTerrain, 0);
96 				}
97 			}
98 		}
99 	}
100 
101 
102 	// ------ checking exit -------//
103 	// if an exit is set, no exit is scanned in next 7 squares
104 	const int MIN_EXIT_SEPARATION = 7;
105 	int lastExit;
106 
107 	// ------ scan for south exit, width 1 --------//
108 
109 #define SOUTH_PATTERN1 11
110 #define SOUTH_PATTERN2 15
111 #define SOUTH_PATTERN3 19
112 #define SOUTH_PATTERN4 23
113 #define IS_SOUTH_EXIT_PATTERN(h) (h==SOUTH_PATTERN1 || h==SOUTH_PATTERN2 || h==SOUTH_PATTERN3 || h==SOUTH_PATTERN4)
114 #define SOUTH_LEFT_SPECIAL 'B'
115 #define SOUTH_RIGHT_SPECIAL 'C'
116 #define SOUTH_CENTRE_SPECIAL 'A'
117 
118 	for( y = 1; y < max_y_loc-1; ++y)
119 	{
120 		lastExit = 0;
121 		x=0;
122 		locPtr=get_loc(x,y);
123 		for( ; x < max_x_loc-2; ++x, ++locPtr, lastExit=lastExit>0?lastExit-1:0 )
124 		{
125 			HillBlockInfo *h1, *h2, *h3;
126 			char h1p, h2p, h3p;
127 			// three hill blocks on a row are pattern 11,15,19 or 23,
128 			// block above the second block is a walkable
129 			if( !lastExit && locPtr->has_hill()
130 				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
131 				&& !h1->special_flag
132 				&& (h1p = h1->pattern_id)
133 				&& IS_SOUTH_EXIT_PATTERN(h1p)
134 				&& (locPtr+1)->has_hill()
135 				&& (h2=hill_res[(locPtr+1)->hill_id1()])->priority == HIGH_HILL_PRIORITY
136 				&& (h2p = h2->pattern_id)
137 				&& IS_SOUTH_EXIT_PATTERN(h2p)
138 				&& (locPtr+2)->has_hill()
139 				&& (h3=hill_res[(locPtr+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
140 				&& (h3p = h3->pattern_id)
141 				&& IS_SOUTH_EXIT_PATTERN(h3p)
142 				&& get_loc(x+1, y-1)->walkable() )
143 			{
144 				short hillId, terrainId;
145 				Location *loc2;
146 
147 				// change this square
148 				if( h1p == SOUTH_PATTERN3)
149 					h1p = SOUTH_PATTERN1;
150 				else if( h1p == SOUTH_PATTERN4)
151 					h1p = SOUTH_PATTERN2;
152 				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, SOUTH_LEFT_SPECIAL, 0);
153 				locPtr->remove_hill();
154 				locPtr->set_hill(hillId);
155 				//### begin alex 24/6 ###//
156 				locPtr->set_power_off();
157 				set_surr_power_off(x, y);
158 				//#### end alex 24/6 ####//
159 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
160 					0, 0, 1, 0 )) != 0 )
161 					locPtr->terrain_id = terrainId;
162 				err_when( locPtr->has_hill() && locPtr->walkable());
163 
164 				// next row
165 				loc2 = get_loc(x, y+1);
166 				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
167 					LOW_HILL_PRIORITY, SOUTH_LEFT_SPECIAL);
168 				if( !loc2->hill_id2() )
169 				{
170 					// if the location has only one block, remove it
171 					// if the location has two block, the bottom one is replaced
172 					loc2->remove_hill();
173 				}
174 				loc2->set_hill(hillId);
175 				//### begin alex 24/6 ###//
176 				loc2->set_power_off();
177 				set_surr_power_off(x, y+1);
178 				//#### end alex 24/6 ####//
179 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
180 					0, 0, 1, 0)) != 0 )
181 					loc2->terrain_id = terrainId;
182 				err_when( loc2->has_hill() && loc2->walkable());
183 
184 				// second square
185 				loc2 = get_loc(x+1, y);
186 				loc2->remove_hill();
187 				loc2->walkable_reset();
188 				// ##### begin Gilbert 14/10 #####//
189 				//if((terrainId = terrain_res.scan(terrainType, terrainType,
190 				//	0, 0, 1, 0)) != 0 )
191 				if((terrainId = terrain_res.scan( terrainType, BOTTOM_MASK, terrainType,
192 					BOTTOM_MASK, terrainType, BOTTOM_MASK, terrainType, BOTTOM_MASK)) != 0)
193 				// ##### end Gilbert 14/10 #####//
194 					loc2->terrain_id = terrainId;
195 				err_when( loc2->has_hill() && loc2->walkable());
196 
197 				// next row
198 				loc2 = get_loc(x+1, y+1);
199 				loc2->remove_hill();
200 				loc2->walkable_reset();
201 				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
202 					SOUTH_PATTERN2, 0, 1, SOUTH_CENTRE_SPECIAL )) != 0 )
203 					loc2->terrain_id = terrainId;
204 				err_when( loc2->has_hill() && loc2->walkable());
205 
206 				// prev row
207 				// loc2 = get_loc(x+1, y-1);
208 				// if((terrainId = terrain_res.scan(terrainType, terrainType-1,
209 				// 	SOUTH_PATTERN2, 0, 1, SOUTH_CENTRE_SPECIAL )) != 0 )
210 				//	loc2->terrain_id = terrainId;
211 				// err_when( loc2->has_hill() && loc2->walkable());
212 
213 				// third square
214 				loc2 = get_loc(x+2, y);
215 				if( h3p == SOUTH_PATTERN4)
216 					h3p = SOUTH_PATTERN1;
217 				if( h3p == SOUTH_PATTERN3)
218 					h3p = SOUTH_PATTERN2;
219 				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, SOUTH_RIGHT_SPECIAL, 0);
220 				loc2->remove_hill();
221 				loc2->set_hill(hillId);
222 				//### begin alex 24/6 ###//
223 				loc2->set_power_off();
224 				set_surr_power_off(x+2, y);
225 				//#### end alex 24/6 ####//
226 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
227 					0, 0, 1, 0)) != 0 )
228 					loc2->terrain_id = terrainId;
229 				err_when( loc2->has_hill() && loc2->walkable());
230 
231 				// next row
232 				loc2 = get_loc(x+2, y+1);
233 				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
234 					LOW_HILL_PRIORITY, SOUTH_RIGHT_SPECIAL);
235 				if( !loc2->hill_id2() )
236 				{
237 					// if the location has only one block, remove it
238 					// if the location has two block, the bottom one is replaced
239 					loc2->remove_hill();
240 				}
241 				loc2->set_hill(hillId);
242 				//### begin alex 24/6 ###//
243 				loc2->set_power_off();
244 				set_surr_power_off(x+2, y+1);
245 				//#### end alex 24/6 ####//
246 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
247 					0, 0, 1, 0)) != 0 )
248 					loc2->terrain_id = terrainId;
249 				err_when( loc2->has_hill() && loc2->walkable());
250 
251 				lastExit = MIN_EXIT_SEPARATION;
252 			}
253 		}
254 	}
255 
256 
257 	// ------ scan for north exit, width 1 --------//
258 
259 #define NORTH_PATTERN1 12
260 #define NORTH_PATTERN2 16
261 #define NORTH_PATTERN3 20
262 #define NORTH_PATTERN4 24
263 #define IS_NORTH_EXIT_PATTERN(h) (h==NORTH_PATTERN1 || h==NORTH_PATTERN2 || h==NORTH_PATTERN3 || h==NORTH_PATTERN4)
264 #define NORTH_LEFT_SPECIAL 'D'
265 #define NORTH_RIGHT_SPECIAL 'E'
266 #define NORTH_CENTRE_SPECIAL 'F'
267 
268 	for( y = 1; y < max_y_loc-2; ++y)
269 	{
270 		lastExit = 0;
271 		x = max_x_loc-3; // x=0;
272 		locPtr=get_loc(x,y);
273 		for( ; x >= 0; --x, --locPtr, lastExit=lastExit>0?lastExit-1:0)
274 		{
275 			HillBlockInfo *h1, *h2, *h3;
276 			char h1p, h2p, h3p;
277 			// three hill blocks on a row are pattern 12,16,20 or 24,
278 			// block below the second block is a walkable
279 			if( !lastExit && locPtr->has_hill()
280 				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
281 				&& !h1->special_flag
282 				&& (h1p = h1->pattern_id)
283 				&& IS_NORTH_EXIT_PATTERN(h1p)
284 				&& (locPtr+1)->has_hill()
285 				&& (h2=hill_res[(locPtr+1)->hill_id1()])->priority == HIGH_HILL_PRIORITY
286 				&& (h2p = h2->pattern_id)
287 				&& IS_NORTH_EXIT_PATTERN(h2p)
288 				&& (locPtr+2)->has_hill()
289 				&& (h3=hill_res[(locPtr+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
290 				&& (h3p = h3->pattern_id)
291 				&& IS_NORTH_EXIT_PATTERN(h3p)
292 				&& get_loc(x+1, y+1)->walkable() )
293 			{
294 				short hillId, terrainId;
295 				Location *loc2;
296 
297 				// change this square
298 				if( h1p == NORTH_PATTERN4)
299 					h1p = NORTH_PATTERN1;
300 				else if( h1p == NORTH_PATTERN3)
301 					h1p = NORTH_PATTERN2;
302 				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, NORTH_LEFT_SPECIAL, 0);
303 				locPtr->remove_hill();
304 				locPtr->set_hill(hillId);
305 				//### begin alex 24/6 ###//
306 				locPtr->set_power_off();
307 				set_surr_power_off(x, y);
308 				//#### end alex 24/6 ####//
309 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
310 					0, 0, 1, 0)) != 0 )
311 					locPtr->terrain_id = terrainId;
312 				err_when( locPtr->has_hill() && locPtr->walkable());
313 
314 				// second square
315 				loc2 = get_loc(x+1, y);
316 				loc2->remove_hill();
317 				loc2->walkable_reset();
318 				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
319 				//	0, 0, 1, NORTH_CENTRE_SPECIAL)) != 0 )
320 				//	loc2->terrain_id = terrainId;
321 				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
322 					NORTH_PATTERN2, 0, 1, NORTH_CENTRE_SPECIAL )) != 0 )
323 					loc2->terrain_id = terrainId;
324 				err_when( loc2->has_hill() && loc2->walkable());
325 
326 				// next row
327 				//loc2 = get_loc(x+1, y+1);
328 				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
329 				//	NORTH_PATTERN2, 0, 1, NORTH_CENTRE_SPECIAL )) != 0 )
330 				//	loc2->terrain_id = terrainId;
331 				//err_when( loc2->has_hill() && loc2->walkable());
332 
333 				// third square
334 				loc2 = get_loc(x+2, y);
335 				if( h3p == NORTH_PATTERN3)
336 					h3p = NORTH_PATTERN1;
337 				if( h3p == NORTH_PATTERN4)
338 					h3p = NORTH_PATTERN2;
339 				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, NORTH_RIGHT_SPECIAL, 0);
340 				loc2->remove_hill();
341 				loc2->set_hill(hillId);
342 				//### begin alex 24/6 ###//
343 				loc2->set_power_off();
344 				set_surr_power_off(x+2, y);
345 				//#### end alex 24/6 ####//
346 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
347 					0, 0, 1, 0)) != 0 )
348 					loc2->terrain_id = terrainId;
349 				err_when( loc2->has_hill() && loc2->walkable());
350 
351 				lastExit = MIN_EXIT_SEPARATION;
352 			}
353 		}
354 	}
355 
356 
357 	// ------ scan for west exit, width 1 --------//
358 
359 #define WEST_PATTERN1 9
360 #define WEST_PATTERN2 13
361 #define WEST_PATTERN3 17
362 #define WEST_PATTERN4 21
363 #define IS_WEST_EXIT_PATTERN(h) (h==WEST_PATTERN1 || h==WEST_PATTERN2 || h==WEST_PATTERN3 || h==WEST_PATTERN4)
364 #define WEST_TOP_SPECIAL 'G'
365 #define WEST_BOTTOM_SPECIAL 'I'
366 #define WEST_CENTRE_SPECIAL 'H'
367 
368 	for( x = 1; x < max_x_loc-1; ++x)
369 	{
370 		lastExit = 0;
371 		for( y = 0; y < max_y_loc-4; ++y, lastExit=lastExit>0?lastExit-1:0)
372 		{
373 			locPtr=get_loc(x,y);
374 			HillBlockInfo *h1, *h2, *h3;
375 			char h1p, h2p, h3p;
376 			// three hill blocks on a row are pattern 9, 13, 17, 21
377 			// block above the second block is a walkable
378 			if( !lastExit && locPtr->has_hill()
379 				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
380 				&& !h1->special_flag
381 				&& (h1p = h1->pattern_id)
382 				&& IS_WEST_EXIT_PATTERN(h1p)
383 				&& get_loc(x,y+1)->has_hill()
384 				&& get_loc(x,y+2)->has_hill()
385 				&& (h2=hill_res[get_loc(x,y+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
386 				&& (h2p = h2->pattern_id)
387 				&& IS_WEST_EXIT_PATTERN(h2p)
388 				&& get_loc(x,y+3)->has_hill()
389 				&& (h3=hill_res[get_loc(x,y+3)->hill_id1()])->priority == HIGH_HILL_PRIORITY
390 				&& (h3p = h3->pattern_id)
391 				&& (h3p == WEST_PATTERN1 || h3p == WEST_PATTERN4)
392 				&& get_loc(x+1, y+2)->walkable() )
393 			{
394 				short hillId, terrainId, hill2;
395 				Location *loc2;
396 
397 				// change this square
398 				if( h1p == WEST_PATTERN3)
399 					h1p = WEST_PATTERN1;
400 				else if( h1p == WEST_PATTERN4)
401 					h1p = WEST_PATTERN2;
402 				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, WEST_TOP_SPECIAL, 0);
403 				hill2 = locPtr->hill_id2();
404 				locPtr->remove_hill();
405 				locPtr->set_hill(hillId);
406 				//### begin alex 24/6 ###//
407 				locPtr->set_power_off();
408 				set_surr_power_off(x, y);
409 				//#### end alex 24/6 ####//
410 				if( hill2 )
411 					locPtr->set_hill(hill2);
412 				err_when( locPtr->has_hill() && locPtr->walkable());
413 
414 				// next row
415 				loc2 = get_loc(x, y+1);
416 				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
417 					LOW_HILL_PRIORITY, WEST_TOP_SPECIAL);
418 				loc2->remove_hill();
419 				loc2->set_hill(hillId);
420 				//### begin alex 24/6 ###//
421 				loc2->set_power_off();
422 				set_surr_power_off(x, y+1);
423 				//#### end alex 24/6 ####//
424 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
425 					0, 0, 1, 0)) != 0 )
426 					loc2->terrain_id = terrainId;
427 				err_when( loc2->has_hill() && loc2->walkable());
428 
429 				// third row
430 				loc2 = get_loc(x, y+2);
431 				loc2->remove_hill();
432 				loc2->walkable_reset();
433 				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
434 				//	0, 0, 1, WEST_CENTRE_SPECIAL)) != 0 )
435 				//	loc2->terrain_id = terrainId;
436 				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
437 					WEST_PATTERN2, 0, 1, WEST_CENTRE_SPECIAL )) != 0 )
438 					loc2->terrain_id = terrainId;
439 				err_when( loc2->has_hill() && loc2->walkable());
440 
441 				// next column
442 				//loc2 = get_loc(x+1, y+2);
443 				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
444 				//	WEST_PATTERN2, 0, 1, WEST_CENTRE_SPECIAL )) != 0 )
445 				//	loc2->terrain_id = terrainId;
446 				//err_when( loc2->has_hill() && loc2->walkable());
447 
448 				// fourth row
449 				loc2 = get_loc(x, y+3);
450 				if( h3p == WEST_PATTERN4)
451 					h3p = WEST_PATTERN1;
452 				if( h3p == WEST_PATTERN3)
453 					h3p = WEST_PATTERN2;
454 				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, WEST_BOTTOM_SPECIAL, 0);
455 				loc2->remove_hill();
456 				loc2->set_hill(hillId);
457 				//### begin alex 24/6 ###//
458 				loc2->set_power_off();
459 				set_surr_power_off(x, y+3);
460 				//#### end alex 24/6 ####//
461 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
462 					0, 0, 1, 0 )) != 0 )
463 					loc2->terrain_id = terrainId;
464 				err_when( loc2->has_hill() && loc2->walkable());
465 
466 				// next row
467 				loc2 = get_loc(x, y+4);
468 				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
469 					LOW_HILL_PRIORITY, WEST_BOTTOM_SPECIAL);
470 				loc2->set_hill(hillId);
471 				//### begin alex 24/6 ###//
472 				loc2->set_power_off();
473 				set_surr_power_off(x, y+4);
474 				//#### end alex 24/6 ####//
475 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
476 					0, 0, 1, 0)) != 0 )
477 					loc2->terrain_id = terrainId;
478 				err_when( loc2->has_hill() && loc2->walkable());
479 				lastExit = MIN_EXIT_SEPARATION;
480 			}
481 		}
482 	}
483 
484 	// ------ scan for east exit, width 1 --------//
485 
486 #define EAST_PATTERN1 10
487 #define EAST_PATTERN2 14
488 #define EAST_PATTERN3 18
489 #define EAST_PATTERN4 22
490 #define IS_EAST_EXIT_PATTERN(h) (h==EAST_PATTERN1 || h==EAST_PATTERN2 || h==EAST_PATTERN3 || h==EAST_PATTERN4)
491 #define EAST_TOP_SPECIAL 'J'
492 #define EAST_BOTTOM_SPECIAL 'L'
493 #define EAST_CENTRE_SPECIAL 'K'
494 
495 	for( x=1; x < max_x_loc-1; ++x)
496 	{
497 		lastExit = 0;
498 		for( y = max_y_loc-5; y >= 0; --y, lastExit=lastExit>0?lastExit-1:0)
499 		{
500 			locPtr=get_loc(x,y);
501 			HillBlockInfo *h1, *h2, *h3;
502 			char h1p, h2p, h3p;
503 			// three hill blocks on a row are pattern 9, 13, 17, 21
504 			// block above the second block is a walkable
505 			if( !lastExit && locPtr->has_hill()
506 				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
507 				&& !h1->special_flag
508 				&& (h1p = h1->pattern_id)
509 				&& IS_EAST_EXIT_PATTERN(h1p)
510 				&& get_loc(x,y+1)->has_hill()
511 				&& get_loc(x,y+2)->has_hill()
512 				&& (h2=hill_res[get_loc(x,y+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
513 				&& (h2p = h2->pattern_id)
514 				&& IS_EAST_EXIT_PATTERN(h2p)
515 				&& get_loc(x,y+3)->has_hill()
516 				&& (h3=hill_res[get_loc(x,y+3)->hill_id1()])->priority == HIGH_HILL_PRIORITY
517 				&& (h3p = h3->pattern_id)
518 				&& (h3p == EAST_PATTERN1 || h3p == EAST_PATTERN4)
519 				&& get_loc(x-1, y+2)->walkable() )
520 			{
521 				short hillId, terrainId, hill2;
522 				Location *loc2;
523 
524 				// change this square
525 				if( h1p == EAST_PATTERN3)
526 					h1p = EAST_PATTERN1;
527 				else if( h1p == EAST_PATTERN4)
528 					h1p = EAST_PATTERN2;
529 				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, EAST_TOP_SPECIAL, 0);
530 				hill2 = locPtr->hill_id2();
531 				locPtr->remove_hill();
532 				locPtr->set_hill(hillId);
533 				if( hill2 )
534 					locPtr->set_hill(hill2);
535 				err_when( locPtr->has_hill() && locPtr->walkable());
536 				//### begin alex 24/6 ###//
537 				locPtr->set_power_off();
538 				set_surr_power_off(x, y);
539 				//#### end alex 24/6 ####//
540 
541 				// next row
542 				loc2 = get_loc(x, y+1);
543 				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
544 					LOW_HILL_PRIORITY, EAST_TOP_SPECIAL);
545 				loc2->remove_hill();
546 				loc2->set_hill(hillId);
547 				//### begin alex 24/6 ###//
548 				loc2->set_power_off();
549 				set_surr_power_off(x, y+1);
550 				//#### end alex 24/6 ####//
551 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
552 					0, 0, 1, 0)) != 0 )
553 					loc2->terrain_id = terrainId;
554 				err_when( loc2->has_hill() && loc2->walkable());
555 
556 				// third row
557 				loc2 = get_loc(x, y+2);
558 				loc2->remove_hill();
559 				loc2->walkable_reset();
560 				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
561 				//	0, 0, 1, EAST_CENTRE_SPECIAL)) != 0 )
562 				//	loc2->terrain_id = terrainId;
563 				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
564 					EAST_PATTERN2, 0, 1, EAST_CENTRE_SPECIAL )) != 0 )
565 					loc2->terrain_id = terrainId;
566 				err_when( loc2->has_hill() && loc2->walkable());
567 
568 				// next column
569 				//loc2 = get_loc(x-1, y+2);
570 				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
571 				//	EAST_PATTERN2, 0, 1, EAST_CENTRE_SPECIAL )) != 0 )
572 				//	loc2->terrain_id = terrainId;
573 				//err_when( loc2->has_hill() && loc2->walkable());
574 
575 				// fourth row
576 				loc2 = get_loc(x, y+3);
577 				if( h3p == EAST_PATTERN4)
578 					h3p = EAST_PATTERN1;
579 				if( h3p == EAST_PATTERN3)
580 					h3p = EAST_PATTERN2;
581 				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, EAST_BOTTOM_SPECIAL, 0);
582 				loc2->remove_hill();
583 				loc2->set_hill(hillId);
584 				//### begin alex 24/6 ###//
585 				loc2->set_power_off();
586 				set_surr_power_off(x, y+3);
587 				//#### end alex 24/6 ####//
588 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
589 					0, 0, 1, 0)) != 0 )
590 					loc2->terrain_id = terrainId;
591 				err_when( loc2->has_hill() && loc2->walkable());
592 
593 				// next row
594 				loc2 = get_loc(x, y+4);
595 				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
596 					LOW_HILL_PRIORITY, EAST_BOTTOM_SPECIAL);
597 				loc2->set_hill(hillId);
598 				//### begin alex 24/6 ###//
599 				loc2->set_power_off();
600 				set_surr_power_off(x, y+4);
601 				//#### end alex 24/6 ####//
602 				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
603 					0, 0, 1, 0)) != 0 )
604 					loc2->terrain_id = terrainId;
605 				err_when( loc2->has_hill() && loc2->walkable());
606 				lastExit = MIN_EXIT_SEPARATION;
607 			}
608 		}
609 	}
610 }
611 // ---------- end of function World::gen_hills -------//
612 
613 
614 // ---------- begin of function World::put_hill_set ------//
put_hill_set(short * px,short * py,short hSetId)615 void World::put_hill_set(short *px, short *py, short hSetId)
616 {
617 }
618 // ---------- end of function World::put_hill_pattern ------//
619 
620 
621 // ---------- begin of function World::put_hill_pattern ------//
put_hill_pattern(short * px,short * py,unsigned char patternId)622 void World::put_hill_pattern(short *px, short *py, unsigned char patternId)
623 {
624 }
625 // ---------- end of function World::put_hill_pattern ------//
626 
627 
628 // ---------- begin of function World::fill_hill -------//
fill_hill(short x,short y)629 void World::fill_hill(short x, short y)
630 {
631 }
632 // ---------- end of function World::fill_hill -------//
633