This might be simpler than we thought. Define a new Location= parameter, "water" which maps to the enumerated constant Fluss (are we continuing to code in German?):
diff --git a/besch/fabrik_besch.h b/besch/fabrik_besch.h
index a672728..f3d59f6 100644
--- a/besch/fabrik_besch.h
+++ b/besch/fabrik_besch.h
@@ -210,7 +210,7 @@ class fabrik_besch_t : public obj_besch_t {
friend class factory_reader_t;
public:
- enum site_t { Land, Wasser, Stadt };
+ enum site_t { Land, Wasser, Stadt, Fluss };
private:
site_t platzierung; //"placement" (Babelfish)
diff --git a/besch/writer/factory_writer.cc b/besch/writer/factory_writer.cc
index ba84a67..5de002c 100644
--- a/besch/writer/factory_writer.cc
+++ b/besch/writer/factory_writer.cc
@@ -158,6 +158,7 @@ void factory_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj
!STRICMP(placing, "land") ? fabrik_besch_t::Land :
!STRICMP(placing, "water") ? fabrik_besch_t::Wasser :
!STRICMP(placing, "city") ? fabrik_besch_t::Stadt :
+ !STRICMP(placing, "river") ? fabrik_besch_t::Fluss :
fabrik_besch_t::Land;
uint16 const produktivitaet = obj.get_int("productivity", 10);
uint16 const bereich = obj.get_int("range", 10);
Then in simwerkz.cc, in the definition of wkz_build_factory_t::work we have …
if(fab->get_platzierung()==fabrik_besch_t::Wasser)
{
// at sea
…
}
else
{
// and on solid ground
hat_platz = welt->square_is_free( k.get_2d(), fab->get_haus()->get_b(rotation), fab->get_haus()->get_h(rotation), NULL, cl );
if(!hat_platz && size.y!=size.x && fab->get_haus()->get_all_layouts()>1 && (default_param==NULL || default_param[1]=='#'))
…
}
if(hat_platz) {
// eventually adjust production
Now, just above the final if(hat_platz) -- "has location" -- add a new code stanza that loops over the prospective factory's borders, looking at each tile that sits outside and immediately adjacent to the factory site, and checks that at least one of those squares is a River square; if none are, clear hat_platz. That's all that's required.
One catch might be that fabrikbauer_t::increase_industry_density has a "retrys" loop that counts to twenty, before giving up on building a factory. If rivers are fairly scarce, that probably will result in no factories being built, although it's worth testing. The constant 20 could be changed to "40 for river factories, 20 for all other."
Also, we might want the river square test to be true only for sufficiently large rivers: mills weren't built next to creeks, but at least moderately sized streams.
Can someone help me write the river-check loop?
A