Author Topic: [schedule_x] get line_x  (Read 230 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

[schedule_x] get line_x
« on: July 26, 2017, 04:16:32 PM »

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

example:
Code: [Select]
schedule.get_line()
I suppose you also need a function that determines if you have a line

example:
Code: [Select]
schedule.has_line()

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4251
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [schedule_x] get line_x
« Reply #1 on: July 26, 2017, 04:33:38 PM »
This is not possible. The schedule does not know where it belongs to.
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [schedule_x] get line_x
« Reply #2 on: July 26, 2017, 06:37:52 PM »
I wanted to simplify this code: :P

Code: [Select]
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).
« Last Edit: July 26, 2017, 06:55:19 PM by Yona-TYT »