The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on July 24, 2017, 08:34:09 PM

Title: [line_x] Remove lines
Post by: Yona-TYT on July 24, 2017, 08:34:09 PM

Is there any command to delete lines?  ???

I can think of an idea to solve this: http://forum.simutrans.com/index.php?topic=17140.msg164387#msg164387

But I need to remove lines to achieve it.  ;)
Title: Re: [line_x] Remove lines
Post by: Dwachs on July 25, 2017, 07:08:01 AM
Please check r8274
Title: Re: [line_x] Remove lines
Post by: Yona-TYT on July 26, 2017, 05:28:19 AM
Quote from: Dwachs on July 25, 2017, 07:08:01 AM
Please check r8274
For some reason the "delete()" function can not be used.  ???

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=372&a=true&file=erorro_delete.png&t=FOglmT1glMqsDKU&scalingup=0)
Title: Re: [line_x] Remove lines
Post by: Dwachs on July 26, 2017, 07:20:30 AM
I see, 'delete' is a language keyword.. will fix tonight.

Edit: fixed in r8275, renamed to 'destroy'
Title: Re: [line_x] Remove lines
Post by: Yona-TYT on July 28, 2017, 03:34:49 AM
It does not work as I expected  :-[ , I need a function that allows disassociating the line of vehicles to eliminate them.

I need to remove the lines that are not used, but I receive an error message when I remove the vehicle.

code:

function checks_all_line(pl)
{
    local list = player_x(pl).get_line_list()
    local l_nr = list.get_count()
    local line = null
    for(local j=0;j<l_nr;j++){
        line = list[j]
        if (line){
            local cov_nr = 0
            local cov_list = line.get_convoy_list()
            foreach(cov in cov_list) {
                cov_nr++
            }
            if (cov_nr>0)
                continue
            else {
                local sch = line.get_schedule()
                local sch_nr = sch.entries.len()
                if (sch && sch_nr==0){
                    line.destroy(player_x(pl))
                }
            }
        }     
    }
    return null
}


(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=372&a=true&file=error_vehic_line.png&t=5n2e5qnL9ODHPC7&scalingup=0)
Title: Re: [line_x] Remove lines
Post by: Dwachs on July 28, 2017, 06:41:32 AM
Why would you like to delete a line in a scenario? It can be done: assign all convoys to another line (or destroy them), then destroy the line.
Title: Re: [line_x] Remove lines
Post by: Yona-TYT on July 28, 2017, 08:39:05 AM
Quote from: Dwachs on July 28, 2017, 06:41:32 AM
Why would you like to delete a line in a scenario? It can be done: assign all convoys to another line (or destroy them), then destroy the line.


I just want to remove the lines that are not used.

Any function to know if the line has associated vehicles ?.
Title: Re: [line_x] Remove lines
Post by: Dwachs on July 29, 2017, 09:17:22 AM
Quote from: Yona-TYT on July 28, 2017, 08:39:05 AM
I just want to remove the lines that are not used.
Imho this is the task of the player.
Quote
Any function to know if the line has associated vehicles ?.

line.get_convoy_list().get_count()==0
Title: Re: [line_x] Remove lines
Post by: Yona-TYT on July 29, 2017, 01:13:35 PM
It's not working for me.  :-[

Script: http://files.simutrans.com/index.php/s/3veHwrenSgcEQun

Savegame: http://files.simutrans.com/index.php/s/L4NXqsHEGABY64W (http://files.simutrans.com/index.php/s/L4NXqsHEGABY64W)

Code: scenario.nut (line 555)
function checks_all_line(pl)
{
    local list = player_x(pl).get_line_list()
    local l_nr = list.get_count()
    local line = null
    for(local j=0;j<l_nr;j++){
        line = list[j]
        if (line){
            local cov_nr = 0
            local cov_list = line.get_convoy_list()

            if (cov_list.get_count()!=0)
                continue

            local sch = line.get_schedule()
            local sch_nr = sch.entries.len()
            if (sch && sch_nr==0){
                line.destroy(player_x(pl))
            }
         
        }     
    }
    return null
}