The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: neroden on May 27, 2024, 02:35:11 AM

Title: Report that a factory chain is built at the location nearest the factory chain
Post by: neroden on May 27, 2024, 02:35:11 AM
While working on merging patches from standard into extended, I found a place where standard would benefit from doing what extended is doing. This has been the code in extended for years, because extended can't use the code in standard.  But this code doesn't rely on anything in extended.  It works, and it's cleaner.

Instead of looking at get_target_cities, this reports the city which the factory is, in fact, actually closest to after it's built.

diff --git a/src/simutrans/builder/fabrikbauer.cc b/src/simutrans/builder/fabrikbauer.cc
index e9ac9f41c..d7bdf17bd 100644
--- a/src/simutrans/builder/fabrikbauer.cc
+++ b/src/simutrans/builder/fabrikbauer.cc
@@ -1098,10 +1098,8 @@ int factory_builder_t::increase_industry_density( bool tell_me )
minimap_t::get_instance()->calc_map_size();
// tell the player
if(tell_me) {
- const char *stadt_name = translator::translate("nowhere");
- if (!our_fab->get_target_cities().empty()) {
- stadt_name = our_fab->get_target_cities()
[0][o]->get_name();
- }
+ stadt_t *s = welt->find_nearest_city( pos.get_2d() );
+ const char *stadt_name = s ? s->get_name() : translator::translate("nowhere");
 cbuffer_t buf;
 buf.printf( translator::translate("New factory chain\nfor %s near\n%s built with\n%i factories."), translator::translate(our_fab->get_name()), stadt_name, nr );
 welt->get_message()->add_message(buf, pos, message_t::industry, CITY_KI, our_fab->get_desc()->get_building()->get_tile(0)->get_background(0, 0, 0));
Title: Re: Report that a factory chain is built at the location nearest the factory chain
Post by: prissi on May 27, 2024, 12:30:31 PM
That code was even used for consumers, so it is even more consistent, thanks. Incorporated in r11242