Skip to content

Commit 0c4b9ae

Browse files
committed
FIX: Transformers are removed by factory field expansion
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11906 8aca7d54-2c30-db11-9de9-000461428c89
1 parent 679ee92 commit 0c4b9ae

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

simutrans/history.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
FIX: not connection to tunnels, bridges and elevated ways when extending city streets
6868
FIX: Overcrowded stops can cause unhappy return passengers in unconnected networks
6969
FIX: Factory editor could not select water factories from climate selection
70+
FIX: Transformers get removed by factory field expansion
7071

7172

7273
Release of 124.3.1 (r11671 on 5-Apr-2025):

src/simutrans/simfab.cc

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
10111028
bool 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);

src/simutrans/simfab.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ class fabrik_t
729729
* returns: Work rate in fixed point form.
730730
*/
731731
static sint32 calculate_work_rate_ramp(sint32 const amount, sint32 const minimum, sint32 const maximum, uint32 const precision = WORK_BITS);
732+
733+
private:
734+
bool can_build_field_on_ground(const grund_t *gr, climate cl) const;
732735
};
733736

734737
#endif

0 commit comments

Comments
 (0)