コード例 #1
0
 public MapNode(FloorNode floor)
 {
     HasElevator        = false;
     HasServiceElevator = false;
     floorNode          = floor;
     nodesOnFloor       = null;
     init();
 }
コード例 #2
0
        public (FloorNode, MapNode) createFloorAndNodeIfApplicable(Slot slot, IPrototype item)
        {
            // Create corresponding FloorNode if not available
            FloorNode f;

            if (!floorNodes.ContainsKey(slot.Y))
            {
                if (!mapNodesByFloor.ContainsKey(slot.Y))
                {
                    mapNodesByFloor[slot.Y] = new List <MapNode>();
                }
                f = new FloorNode(mapNodesByFloor[slot.Y]);
                floorNodes[slot.Y] = f;
                f.position         = new Slot(int.MinValue, slot.Y);
            }
            else
            {
                f = floorNodes[slot.Y];
            }

            if (!(item is IHaulsPeople))
            {
                return(f, null);                     // Building item, do not add into transport
            }
            // Create/Get MapNode for above created floor
            MapNode n;

            if (!peopleMovementMap.ContainsKey(slot.ToString()))
            {
                n = new MapNode(f);
                peopleMovementMap[slot.ToString()] = n;
                n.position = slot;

                // Just insert node if list is empty
                if (mapNodesByFloor[slot.Y].Count == 0)
                {
                    mapNodesByFloor[slot.Y].Add(n);
                }
                else
                {
                    // Look for nearby nodes on same floor to insert
                    MapNode left  = null;
                    MapNode right = null;
                    foreach (MapNode node in mapNodesByFloor[slot.Y])
                    {
                        if (node.position.X < slot.X)
                        {
                            left = node;
                        }
                        else
                        {
                            right = node;
                            var nodeIndex = mapNodesByFloor[slot.Y].IndexOf(node);
                            mapNodesByFloor[slot.Y].Insert(nodeIndex, n);
                            break;
                        }
                    }

                    if (left != null)
                    {
                        if (right == null)
                        {
                            mapNodesByFloor[slot.Y].Add(n);    // Insert node as last node in list
                        }
                        n.neighbours[(int)MapNode.Direction.LEFT]     = left;
                        left.neighbours[(int)MapNode.Direction.RIGHT] = n;
                    }

                    if (right != null)
                    {
                        n.neighbours[(int)MapNode.Direction.RIGHT]    = right;
                        right.neighbours[(int)MapNode.Direction.LEFT] = n;
                    }
                }
            }
            else
            {
                n = peopleMovementMap[slot.ToString()];
            }

            return(f, n);
        }