@@ -93,10 +93,10 @@ void init_fab_map( karte_t *welt )
9393 * @param x,y world position, needs to be valid coordinates
9494 * @returns true, if factory coordinate
9595 */
96- inline bool is_factory_at (sint16 x, sint16 y )
96+ inline bool is_factory_at (koord p )
9797{
98- uint32 idx = (fab_map_w*y)+(x/8 );
99- return idx < fab_map.get_count () && (fab_map[idx]&(1 <<(x%8 )))!=0 ;
98+ uint32 idx = (fab_map_w*p. y )+(p. x /8 );
99+ return idx < fab_map.get_count () && (fab_map[idx]&(1 <<(p. x %8 )))!=0 ;
100100}
101101
102102
@@ -118,9 +118,15 @@ class factory_site_searcher_t: public building_placefinder_t {
118118
119119 bool is_area_ok (koord pos, sint16 w, sint16 h, climate_bits cl) const OVERRIDE
120120 {
121+ // do not build too close to an existing factory
122+ if (is_factory_at (pos) || is_factory_at (pos+koord (w,h))) {
123+ return false ;
124+ }
125+
121126 if ( !building_placefinder_t::is_area_ok (pos, w, h, cl) ) {
122127 return false ;
123128 }
129+
124130 uint16 mincond = 0 ;
125131 uint16 condmet = 0 ;
126132 switch (site) {
@@ -136,19 +142,15 @@ class factory_site_searcher_t: public building_placefinder_t {
136142 }
137143
138144 // needs to run one tile wider than the factory on all sides
139- for (sint16 y = -1 ; y <= h; y++) {
140- for (sint16 x = -1 ; x <= w; x++) {
145+ for (sint16 y = -1 ; y < h; y++) {
146+ for (sint16 x = -1 ; x < w; x++) {
141147 koord k (pos + koord (x,y));
142148 grund_t *gr = welt->lookup_kartenboden (k);
143149 if (!gr) {
144150 return false ;
145151 }
146- // do not build on an existing factory
147- if ( is_factory_at (k.x , k.y ) ) {
148- return false ;
149- }
150152 if ( 0 <= x && x < w && 0 <= y && y < h ) {
151- // actual factorz tile: is there something top like elevated monorails?
153+ // actual factory tile: is there something top like elevated monorails?
152154 if ( gr->get_leitung ()!=NULL || welt->lookup (gr->get_pos ()+koord3d (0 ,0 ,1 ) )!=NULL ) {
153155 // something on top (monorail or power lines)
154156 return false ;
@@ -341,14 +343,19 @@ void factory_builder_t::find_producer(weighted_vector_tpl<const factory_desc_t *
341343
342344bool factory_builder_t::check_construction_site (koord pos, koord size, factory_desc_t ::site_t site, bool is_factory, climate_bits cl)
343345{
346+ // do not build too close or on an existing factory
347+ if (!welt->is_within_limits (pos) || is_factory_at (pos) || is_factory_at (pos+size)) {
348+ return false ;
349+ }
350+
344351 // check for water (no shore in sight!)
345352 if (site==factory_desc_t ::Water) {
346- for ( int y= 0 ;y<size. y ;y++) {
347- for (int x= 0 ;x< size.x ;x ++) {
348- const grund_t *gr=welt-> lookup_kartenboden (pos+ koord (x,y));
349-
353+ // we want at least 3 tiles of empty water around a water factory
354+ for (int y = - 3 ; y < size.y + 3 ; y ++) {
355+ for ( int x = - 3 ; x < size. x + 3 ; x++) {
356+ const grund_t * gr = welt-> lookup_kartenboden (pos + koord (x, y));
350357 // need to check for water buildings (e.g. fisheries)
351- if (gr== NULL || !gr->is_water () || gr->get_grund_hang ()!= slope_t ::flat || gr->find <gebaeude_t >()) {
358+ if (gr == NULL || !gr->is_water () || gr->get_grund_hang () != slope_t ::flat || gr->find <gebaeude_t >()) {
352359 return false ;
353360 }
354361 }
@@ -359,11 +366,6 @@ bool factory_builder_t::check_construction_site(koord pos, koord size, factory_d
359366 return factory_site_searcher_t (welt, site).is_area_ok (pos, size.x , size.y , cl);
360367 }
361368 else {
362- // check on land
363- // do not build too close or on an existing factory
364- if ( !welt->is_within_limits (pos) || is_factory_at (pos.x , pos.y ) ) {
365- return false ;
366- }
367369 return welt->square_is_free (pos, size.x , size.y , NULL , cl);
368370 }
369371 }
@@ -376,11 +378,6 @@ koord3d factory_builder_t::find_random_construction_site(koord pos, int radius,
376378 bool is_factory = desc->get_type ()==building_desc_t ::factory;
377379 bool wasser = site == factory_desc_t ::Water;
378380
379- if (wasser) {
380- // to ensure at least 3x3 water around (maybe this should be the station catchment area+1?)
381- size += koord (6 ,6 );
382- }
383-
384381 climate_bits climates = !ignore_climates ? desc->get_allowed_climate_bits () : ALL_CLIMATES;
385382 if (ignore_climates && site != factory_desc_t ::Water) {
386383 // site = factory_desc_t::Land;
@@ -418,10 +415,6 @@ koord3d factory_builder_t::find_random_construction_site(koord pos, int radius,
418415 return koord3d::invalid;
419416
420417finish:
421- if (wasser) {
422- // take care of offset
423- return welt->lookup_kartenboden (k+koord (3 , 3 ))->get_pos ();
424- }
425418 return welt->lookup_kartenboden (k)->get_pos ();
426419}
427420
0 commit comments