@@ -1006,6 +1006,23 @@ void fabrik_t::build(sint32 rotate, bool build_fields, bool force_initial_prodba
10061006}
10071007
10081008
1009+ bool fabrik_t::can_build_field_on_ground (const grund_t *gr, climate cl) const
1010+ {
1011+ if (!gr) return false ;
1012+ if (gr->get_typ () != grund_t ::boden || !gr->ist_natur ()) return false ;
1013+ if (gr->get_grund_hang () != slope_t ::flat) return false ;
1014+ if (!this ->get_desc ()->get_building ()->is_allowed_climate (cl)) return false ;
1015+
1016+ // Do not remove transformers of solar farms etc.
1017+ if (gr->find <pumpe_t >() || gr->find <senke_t >()) return false ;
1018+
1019+ // allow building fields below power lines
1020+ if (gr->kann_alle_obj_entfernen (NULL ) != NULL && !gr->find <leitung_t >()) return false ;
1021+
1022+ return true ;
1023+ }
1024+
1025+
10091026/* field generation code
10101027 */
10111028bool fabrik_t::add_random_field (uint16 probability)
@@ -1024,18 +1041,15 @@ bool fabrik_t::add_random_field(uint16 probability)
10241041 uint8 radius = 1 ;
10251042
10261043 // pick a coordinate to use - create a list of valid locations and choose a random one
1027- slist_tpl <grund_t *> build_locations;
1044+ vector_tpl <grund_t *> build_locations;
10281045 do {
10291046 for (sint32 xoff = -radius; xoff < radius + get_desc ()->get_building ()->get_size ().x ; xoff++) {
10301047 for (sint32 yoff =-radius ; yoff < radius + get_desc ()->get_building ()->get_size ().y ; yoff++) {
10311048 // if we can build on this tile then add it to the list
1032- grund_t *gr = welt->lookup_kartenboden (pos.get_2d ()+koord (xoff,yoff));
1033- if (gr != NULL &&
1034- gr->get_typ () == grund_t ::boden &&
1035- get_desc ()->get_building ()->is_allowed_climate (welt->get_climate (pos.get_2d ()+koord (xoff,yoff))) &&
1036- gr->get_grund_hang () == slope_t ::flat &&
1037- gr->ist_natur () &&
1038- (gr->find <leitung_t >() || gr->kann_alle_obj_entfernen (NULL ) == NULL )) {
1049+ const planquadrat_t *plan = welt->access (pos.get_2d () + koord (xoff, yoff));
1050+ grund_t *gr = plan->get_kartenboden ();
1051+
1052+ if (this ->can_build_field_on_ground (gr, plan->get_climate ())) {
10391053 // only on same height => climate will match!
10401054 build_locations.append (gr);
10411055 assert (gr->find <field_t >() == NULL );
@@ -1050,14 +1064,17 @@ bool fabrik_t::add_random_field(uint16 probability)
10501064 radius++;
10511065 }
10521066 } while (radius < 10 && build_locations.empty ());
1053- // built on one of the positions
1054- if (!build_locations.empty ()) {
1055- grund_t *gr = build_locations.at (simrand (build_locations.get_count ()));
1067+
1068+ // build on one of the positions
1069+ while (!build_locations.empty ()) {
1070+ grund_t *gr = build_locations[simrand (build_locations.get_count ())];
10561071 leitung_t * lt = gr->find <leitung_t >();
1072+
10571073 if (lt) {
10581074 gr->obj_remove (lt);
10591075 }
10601076 gr->obj_loesche_alle (NULL );
1077+
10611078 // first make foundation below
10621079 const koord k = gr->get_pos ().get_2d ();
10631080 field_data_t new_field (k);
0 commit comments