Пример #1
0
        public override IEnumerable <Node> GetReachableNodes()
        {
            if (!Anchored)
            {
                yield break;
            }

            var entMan    = IoCManager.Resolve <IEntityManager>();
            var grid      = IoCManager.Resolve <IMapManager>().GetGrid(IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(Owner).GridID);
            var gridIndex = grid.TileIndicesFor(IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(Owner).Coordinates);

            // While we go over adjacent nodes, we build a list of blocked directions due to
            // incoming or outgoing wire terminals.
            var terminalDirs = 0;
            List <(Direction, Node)> nodeDirs = new();

            foreach (var(dir, node) in NodeHelpers.GetCardinalNeighborNodes(entMan, grid, gridIndex))
            {
                if (node is CableNode && node != this)
                {
                    nodeDirs.Add((dir, node));
                }

                if (node is CableDeviceNode && dir == Direction.Invalid)
                {
                    // device on same tile
                    nodeDirs.Add((Direction.Invalid, node));
                }

                if (node is CableTerminalNode)
                {
                    if (dir == Direction.Invalid)
                    {
                        // On own tile, block direction it faces
                        terminalDirs |= 1 << (int)IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(node.Owner).LocalRotation.GetCardinalDir();
                    }
                    else
                    {
                        var terminalDir = IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(node.Owner).LocalRotation.GetCardinalDir();
                        if (terminalDir.GetOpposite() == dir)
                        {
                            // Target tile has a terminal towards us, block the direction.
                            terminalDirs |= 1 << (int)dir;
                            break;
                        }
                    }
                }
            }

            foreach (var(dir, node) in nodeDirs)
            {
                // If there is a wire terminal connecting across this direction, skip the node.
                if (dir != Direction.Invalid && (terminalDirs & (1 << (int)dir)) != 0)
                {
                    continue;
                }

                yield return(node);
            }
        }
        public override IEnumerable <Node> GetReachableNodes()
        {
            if (!Anchored)
            {
                yield break;
            }

            if (IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(Owner).GridID == GridId.Invalid)
            {
                yield break; // No funny nodes in spess.
            }
            var entMan    = IoCManager.Resolve <IEntityManager>();
            var grid      = IoCManager.Resolve <IMapManager>().GetGrid(IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(Owner).GridID);
            var gridIndex = grid.TileIndicesFor(IoCManager.Resolve <IEntityManager>().GetComponent <TransformComponent>(Owner).Coordinates);

            var nodes = NodeHelpers.GetCardinalNeighborNodes(entMan, grid, gridIndex, includeSameTile: false);

            foreach (var(_, node) in nodes)
            {
                if (node is CableTerminalNode)
                {
                    yield return(node);
                }
            }
        }
Пример #3
0
        public override IEnumerable <Node> GetReachableNodes()
        {
            var compMgr   = IoCManager.Resolve <IComponentManager>();
            var grid      = IoCManager.Resolve <IMapManager>().GetGrid(Owner.Transform.GridID);
            var gridIndex = grid.TileIndicesFor(Owner.Transform.Coordinates);

            var nodes = NodeHelpers.GetCardinalNeighborNodes(compMgr, grid, gridIndex, includeSameTile: false);

            foreach (var(_, node) in nodes)
            {
                if (node is CableTerminalNode)
                {
                    yield return(node);
                }
            }
        }
        public override IEnumerable <Node> GetReachableNodes(TransformComponent xform,
                                                             EntityQuery <NodeContainerComponent> nodeQuery,
                                                             EntityQuery <TransformComponent> xformQuery,
                                                             IMapGrid?grid,
                                                             IEntityManager entMan)
        {
            if (!xform.Anchored || grid == null)
            {
                yield break;
            }

            var gridIndex = grid.TileIndicesFor(xform.Coordinates);

            var nodes = NodeHelpers.GetCardinalNeighborNodes(nodeQuery, grid, gridIndex, includeSameTile: false);

            foreach (var(_, node) in nodes)
            {
                if (node is CableTerminalNode)
                {
                    yield return(node);
                }
            }
        }