public void executePackageService(ref List<int> way_pass) { if (buf_pack_service.Count == 0) return; if (!buf_pack_service[0].Comeback && !MainForm.findNodeInListById(ID_end, MainForm.Nodes).State || buf_pack_service[0].Comeback && !MainForm.findNodeInListById(ID_start, MainForm.Nodes).State) { buf_pack_service.RemoveAt(0); return; } if (tacts_current >= tacts_needed * buf_pack_service[0].Size * 8 / PackageService.size) { tacts_current = 0; MainForm.CountServiceAccepted++; if (buf_pack_service[0].Comeback) { buf_pack_service[0].WayComeback.RemoveAt(0); if (buf_pack_service[0].WayComeback.Count == 0) buf_pack_service.RemoveAt(0); else { foreach (Channel channel in MainForm.findNodeInListById(buf_pack_service[0].WayComeback[0], MainForm.Nodes).getAllChannels()) if (id_node_start == channel.ID_end && MainForm.findNodeInListById(channel.ID_end, MainForm.Nodes).State) { MainForm.Count_service_sent++; channel.buf_pack_service.Add(new PackageService(buf_pack_service[0])); break; } buf_pack_service.RemoveAt(0); } } else { bool comeback = true; bool way_found; foreach (Channel channel in MainForm.findNodeInListById(id_node_end, MainForm.Nodes).getAllChannels()) { if (!MainForm.findNodeInListById(channel.ID_end, MainForm.Nodes).State) continue; way_found = true; foreach(int id_node in way_pass) if (id_node == channel.ID_end) { way_found = false; break; } if(way_found) { MainForm.Count_service_sent++; comeback = false; PackageService package_service_tmp = new PackageService(buf_pack_service[0]); package_service_tmp.WayComeback.Add(channel.ID_end); channel.buf_pack_service.Add(new PackageService(package_service_tmp)); way_pass.Add(channel.ID_end); } } if (comeback) { MainForm.Count_service_sent++; buf_pack_service[0].Comeback = true; buf_pack_service[0].WayComeback.Reverse(); buf_pack_service[0].WayComeback.RemoveAt(0); } else buf_pack_service.RemoveAt(0); } } else tacts_current++; }
public PackageService(PackageService p) { id_node_start = p.id_node_start; comeback = p.comeback; way_comeback = new List<int>(p.way_comeback); }