The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Yona-TYT on August 23, 2021, 03:27:55 AM

Title: Get tile_list () from building_x ()
Post by: Yona-TYT on August 23, 2021, 03:27:55 AM
 
 I was trying to implement this, to make life easier for scripts:
Code: [Select]
        local tile_list = build.get_tile_list() //It is not implemented
        foreach(tile in tile_list){
            tile.find_object(mo_building).mark()
        }

 But I found that it is not as easy as I expected hehehehe. ;D 
I was trying to generate a list in "gebaeude_t", but I have no idea how to make it work.

Attached my experiment so far: 
Title: Re: Get tile_list () from building_x ()
Post by: Sirius on August 23, 2021, 09:35:01 AM
See gebaeude_t::set_building_tiles, which is not a setter btw, in simutrans extended
Title: Re: Get tile_list () from building_x ()
Post by: Yona-TYT on August 24, 2021, 03:49:27 AM
See gebaeude_t::set_building_tiles, which is not a setter btw, in simutrans extended
However this will not work since I am only able to obtain arrays for coordinates, since there is no real tile_t class.
Title: Re: Get tile_list () from building_x ()
Post by: Sirius on August 24, 2021, 09:35:00 AM
Why doesn't it work?
Surely you cannot use it as-is but it should point you in the right direction:
Either use it as-is and build a C++ function that maps the planquadrat_t to their koord
Code: [Select]
for(planquadrat_t* quadrat : building_tiles){
  result.append(quadrat->get_kartenboden()->get_pos());
}
or build a function on top of it that obtains a list of coordinates instead of planquadrat_t directly.
Title: Re: Get tile_list () from building_x ()
Post by: prissi on August 25, 2021, 12:59:55 PM
foundations (the ground below building) cannot match to koord, only to koord3d. All tiles of the building are at the same height level, hence x,y,fixed hight. So you must lookup the ground at the right height, as there could be more than one ground at one height (stations in tunnel or bridges for instance)

Moreover there is already the function building_get_size();

Anyway, you need to be aware that the tile might not be the rigin. Look fr instance at "void stadt_t::add_gebaeude_to_stadt(" So assuming you are passing a building_x to this routine which is converted to gb Maybe you want something like the attached?
Title: Re: Get tile_list () from building_x ()
Post by: Yona-TYT on August 25, 2021, 03:31:55 PM
I also thought that, a "koord3d" makes more sense, but I was getting carried away by this factory code in simfab.cc:
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 );
            }
        }
    }
}
Although now that I think about it, there are no factories over other factories, it would still be more useful to have a z coordinate.


Your patch works great! Thank you very much!.
Although I'm afraid we are giving the function a bad name since we are not offering a "tile_x" but a "coord3d", so in order not to confuse people it is better to call it "get_coord_list ()", what do you think? .
 We must also change "export_types [" building_x :: get_tile_list "] =" array <coord> () "" by "export_types [" building_x :: get_tile_list "] =" array <coord3d> () ""

This is a functional example:  8)

Code: [Select]
    local t = tile_x(pos.x,pos.y,pos.z)
    local build = t.find_object(mo_building)

    if(build){
        currt_pos = pos
        build.mark()
        local c_list = build.get_coord_list()

        foreach(c in c_list){
            tile_x(c.x, c.y, c.z).find_object(mo_building).mark()
        }
    }

 Well I attach my modification:
 
Title: Re: Get tile_list () from building_x ()
Post by: prissi on September 12, 2021, 03:02:19 AM
Again r10086 should allow for this.
Title: Re: Get tile_list () from building_x ()
Post by: prissi on September 12, 2021, 06:32:53 AM
And r10098 should return a tile tist.
Title: Re: Get tile_list () from building_x ()
Post by: Yona-TYT on September 12, 2021, 11:44:35 AM
And r10098 should return a tile tist.
Wow prisi, you have excelled optimizing and reusing the tile list, congratulations ... and now I have to do some tests 😜.
Title: Re: Get tile_list () from building_x ()
Post by: Yona-TYT on September 13, 2021, 10:30:43 AM
Code: [Select]
        local t_list = build.get_tile_list()

        foreach(t in t_list){
            t.find_object(mo_building).mark()
        }
I am happy that this works well  ;D .