News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Report that a factory chain is built at the location nearest the factory chain

Started by neroden, May 27, 2024, 02:35:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

neroden

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));

prissi

That code was even used for consumers, so it is even more consistent, thanks. Incorporated in r11242