Beispiel #1
0
        // Try to add given cell as neighbour. Returns true when actually added.
        public bool AddNeighbour(Cell cell, ref Vec3 border_point)
        {
            // should not happen - removed due to performance impact - deep down it only checks global ID matching
            if (cell.Equals(this))
            {
                return(false);
            }

            AABB intersection = default(AABB);

            if (AABB.Intersect(cell.AABB, ref intersection, true))
            {
                if (Neighbours.Exists(x => x.cell.GlobalId == cell.GlobalId))
                {
                    return(false);
                }

                AddNeighbour(cell, intersection.Center);
                cell.AddNeighbour(this, intersection.Center);

                border_point = new Vec3(intersection.Center);

                return(true);
            }

            return(false);
        }
Beispiel #2
0
Datei: Cell.cs Projekt: Ifry/Nav
        internal void MakeNeighbours(Cell cell, Vec3 border_point, bool force = false)
        {
            if (!force && Neighbours.Exists(x => x.cell.GlobalId == cell.GlobalId))
            {
                return;
            }

            AddNeighbour(cell, border_point);
            cell.AddNeighbour(this, border_point);
        }
        public void AddNeighbour(City city, double distance)
        {
            var newNeighbour = new Neighbour(city, distance);

            if (!Neighbours.Exists(a => a.Name == newNeighbour.Name))
            {
                Neighbours.Add(newNeighbour);
            }
            if (!city.Neighbours.Exists(a => a.Name == this.Name))
            {
                city.AddNeighbour(this, distance);
            }
        }
Beispiel #4
0
 public void AddNeighbour(Neighbour n)
 {
     if (Neighbours.Exists(ne => ne.ContainsEmployee(n.FromNode, n.ToNode)))
     {
         Neighbour current = Neighbours.Find(ne => ne.ContainsEmployee(n.FromNode, n.ToNode));
         current.ValueForCompany = n.ValueForCompany;
         current.WorkedHours     = n.WorkedHours;
         //Console.WriteLine("TO: " + n.ToNode.Employee.Name);
     }
     else
     {
         Neighbours.Add(n);
     }
 }
Beispiel #5
0
        // Only grid cells connected vis cells with Walk movement flags will be treated as neighbours
        public void AddNeighbour(GridCell grid_cell)
        {
            if (AABB.Intersect(grid_cell.AABB, true) == null)
            {
                return;
            }

            if (Neighbours.Exists(x => x.cell.Equals(grid_cell)))
            {
                return;
            }

            bool         any_cells_connected = false;
            MovementFlag connection_flags    = MovementFlag.None;

            foreach (Cell our_cell in Cells)
            {
                foreach (Cell other_cell in grid_cell.Cells)
                {
                    bool cells_connected = our_cell.AddNeighbour(other_cell);

                    if (cells_connected)
                    {
                        any_cells_connected = true;
                        MovementFlag flags = our_cell.Flags & other_cell.Flags;

                        if (flags > connection_flags)
                        {
                            connection_flags = flags;
                        }
                    }
                }
            }

            if (any_cells_connected)
            {
                Neighbours.Add(new Neighbour(grid_cell, null, connection_flags));
                grid_cell.Neighbours.Add(new Neighbour(this, null, connection_flags));
            }
        }
Beispiel #6
0
        // Try to add given cell as neighbour. Returns true when actually added.
        public bool AddNeighbour(Cell cell)
        {
            if (cell.Equals(this))
            {
                return(false);
            }

            AABB intersection = AABB.Intersect(cell.AABB, true);

            if (intersection != null)
            {
                if (Neighbours.Exists(x => x.cell.GlobalId == cell.GlobalId))
                {
                    return(false);
                }

                AddNeighbour(cell, intersection.Center);
                cell.AddNeighbour(this, intersection.Center);

                return(true);
            }

            return(false);
        }