The International Simutrans Forum

 

Author Topic: factory_x :: get_tile_list () Has a misleading name  (Read 441 times)

0 Members and 1 Guest are viewing this topic.

Online Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
factory_x :: get_tile_list () Has a misleading name
« on: August 25, 2021, 06:32:32 PM »
In the documentation it indicates that:
Quote
Get list of all tiles occupied by buildings belonging to this factory.
      Returns array of tile_x objects
But this is not true since what is obtained is an array of coordinates.

So, wouldn't it be better to change to get_coord_list ()?.
Also, I think it would be more useful to get a "coord3d" than a "coord" in my humble opinion, as @prissi did here:  https://forum.simutrans.com/index.php/topic,21093.msg196741.html#msg196741

Code: [Select]
void fabrik_t::get_tile_list( vector_tpl<koord> &tile_list ) const
{
    tile_list.clear();

    koord pos_2d = pos.get_2d();
    koord size = this->get_desc()->get_building()->get_size(this->get_rotate());
    koord test;
    // Which tiles belong to the fab?
    for( test.x = 0; test.x < size.x; test.x++ ) {
        for( test.y = 0; test.y < size.y; test.y++ ) {
            if( fabrik_t::get_fab( pos_2d+test ) == this ) {
                tile_list.append( pos_2d+test );
            }
        }
    }
}

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #1 on: August 26, 2021, 08:01:26 AM »
Since factories are building, the factory version would be no longer needed.

Online Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #2 on: August 27, 2021, 06:48:55 PM »
Since factories are building, the factory version would be no longer needed.
I have no problem getting rid of this, but we need @Dwachs opinion here.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4913
  • Languages: EN, DE, AT
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #3 on: September 03, 2021, 12:23:55 PM »
Versions for both factory and buildings are needed, as the factory squirrel class is not derived from the building class.

Online Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #4 on: September 04, 2021, 02:25:17 PM »
I wonder why it's called "get_tile_list", shouldn't it be better to call it get_coord_list?.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #5 on: September 12, 2021, 01:29:15 AM »
I submitted the tile list in r10094. I strongly suggest only using the tile list for buildings, even for factories, because of returning koord3d.

Online Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: factory_x :: get_tile_list () Has a misleading name
« Reply #6 on: September 12, 2021, 01:38:52 AM »
Sounds reasonable to me, thanks for implementing @prissi . :D