예제 #1
0
        public override void LowFrequencyUpdate()
        {
            if (!_addedToGraph)
            {
                LogicManager.Instance.Graph.AddNode(_node);
                _addedToGraph = true;
            }

            UpdatePlayerDistanceInfo();

            Int64 targetX = mnX + _xOffset * _searchDist;
            Int64 targetY = mnY + _yOffset * _searchDist;
            Int64 targetZ = mnZ + _zOffset * _searchDist;

            if (_searchDist > _foundDist)
            {
                // Uh oh, we've gone past the target, which means it's disappeared. Make sure we're disconnected from it.
                _node.DisconnectFromHead(OutIndex);
                _found = false;
            }

            if (_node.OutputValues.Length > 0)
            {
                _output = _node.OutputValues[0];
            }

            Segment segment = AttemptGetSegment(targetX, targetY, targetZ);

            if (segment == null)
            {
                return; // We'll try again later.
            }
            UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ);

            ILogicReceiver logicReciever;
            Int32          inputIndex;

            if (CubeHelper.HasEntity(cubeType) &&
                (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null &&
                (inputIndex = logicReciever.FindFaceInputIndex(_targetDirection)) != -1)
            {
                var targetNode = logicReciever.GetLogicNode();

                if (!targetNode.IsInputActive(inputIndex) && _node.OutNodes[OutIndex] != targetNode)
                {
                    // Disconnect and reconnect if the target input is not active or the node is different than previously
                    // The node we found is not the same as the old node

                    if (_searchDist > _foundDist)
                    {
                        // ERROR: This shouldn't happen. We went past the old _foundDist and found something else?
                        Debug.LogWarning("Logic Laser search went past _foundDist? _foundDist: " + _foundDist +
                                         "_searchDist" + _searchDist);
                    }
                    // We've found a different node, so connect to it instead.
                    // Disconnect from logic node at _foundDist and connect to the one at _searchDist.
                    _node.DisconnectFromHead(OutIndex);
                    try
                    {
                        _node.ConnectToHead(OutIndex, targetNode, inputIndex);
                        _foundDist      = _searchDist;
                        _found          = true;
                        _impactPosition = WorldScript.instance.mPlayerFrustrum.GetCoordsToUnity(targetX, targetY, targetZ);
                    }
                    catch (InputEdgeAlreadyActiveException ex)
                    {
                        Debug.LogWarning($"Laser attempted to connect to index that was already in use! Distance: {_searchDist}\n" +
                                         $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" +
                                         "\nException: " + ex);
                    }
                }
                // Else, we've found what we were looking for, don't do anything else

                // Reset the search
                _searchDist = MinSearchDist;
            }
            else if (CubeHelper.IsCubeSolid(cubeType) && !CubeHelper.IsCubeGlass(cubeType) ||
                     _searchDist >= MaxSearchDist || CubeHelper.HasEntity(cubeType))
            {
                // We hit a wall or the max range, reset the search and disconnect from target node
                _searchDist = MinSearchDist;
                _found      = false;
                _node.DisconnectFromHead(OutIndex);
            }
            else
            {
                // Non solid or glass block, increment the search.
                _searchDist++;
            }
        }
예제 #2
0
        public override void LowFrequencyUpdate()
        {
            if (!_addedToGraph)
            {
                LogicManager.Instance.Graph.AddNode(_node);
                _addedToGraph = true;
            }

            Int32 k = -1;

            for (Int32 i = 0; i < FaceCount / 2; i++)
            {
                for (Int32 j = 1; j > -2; j -= 2)
                {
                    k++;
                    if (k == 5)
                    {
                        continue; // Skip over the back direction since it's our input
                    }
                    // Get and check the block at the position
                    Int64 targetX = mnX + _xOffsets[i] * j;
                    Int64 targetY = mnY + _yOffsets[i] * j;
                    Int64 targetZ = mnZ + _zOffsets[i] * j;

                    Segment segment = AttemptGetSegment(targetX, targetY, targetZ);
                    if (segment == null)
                    {
                        continue; // Ignore this one and check the other blocks
                    }
                    UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ);

                    ILogicReceiver logicReciever;
                    Int32          inputIndex;
                    if (CubeHelper.HasEntity(cubeType) &&
                        (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null &&
                        (inputIndex = logicReciever.FindFaceInputIndex(_targetDirections[k])) != -1)
                    {
                        if (logicReciever == this)
                        {
                            Debug.LogError($"Laser Splitter connecting to itself? Loop vars: {i} {j} {k} Target coords: {targetX} {targetY} {targetZ}");
                            continue;
                        }

                        // There is a connectable logic node at the target location
                        var targetNode = logicReciever.GetLogicNode();
                        if (_node.OutNodes[k] == targetNode)
                        {
                            continue; // The current node is the same, no changes needed
                        }
                        // The node is not the same, so remove the old node and connect to the new one.
                        _node.DisconnectFromHead(k);

                        if (!targetNode.IsInputActive(inputIndex))
                        {
                            try
                            {
                                _node.ConnectToHead(k, targetNode, inputIndex);
                            }
                            catch (InputEdgeAlreadyActiveException ex)
                            {
                                Debug.LogWarning(
                                    $"Splitter attempted to connect to index that was already in use! Loop vars: {i} {j} {k}\n" +
                                    $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" +
                                    "\nException: " + ex);
                            }
                        }
                    }
                    else
                    {
                        // No connectable logic node at the target location, make sure we're disconnected
                        _node.DisconnectFromHead(k);
                    }
                }
            }
        }