News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

[schedule_x] get line_x

Started by Yona-TYT, July 26, 2017, 04:16:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


I need to get the line associated with a schedule to simplify the code. ;)

example:
schedule.get_line()

I suppose you also need a function that determines if you have a line

example:
schedule.has_line()

Dwachs

This is not possible. The schedule does not know where it belongs to.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#2
I wanted to simplify this code: :P


function checks_current_line(pl, schedule)
{
    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 && line.is_valid()){
            local sch = line.get_schedule()
            local cov_list = line.get_convoy_list()

            local cov_nr = 0
            foreach(cov in cov_list) {
                cov_nr++
            }
            if (sch && cov_nr==0){
                local entrie = sch.entries
                local sch1_nr = entrie.len()
                local sch2_nr = schedule.entries.len()
                local result = 0
             
                if (sch1_nr>0 && sch1_nr==sch2_nr){
                    for(local i=0;i<sch1_nr;i++){
                        result = is_waystop_correct(pl, schedule, i, entrie[i].load, entrie[i].wait, coord(entrie[i].x, entrie[i].y))
                        if (result != null){
                            break
                        }
                    }
                }
                if (result != null)
                    continue
                else {
                    sch_flag = true
                    return null
                }                 
            }     
        }
    }
    return null
}



This is just to activate a flag if the schedule has a line (when you press the "Promote to line" button).