コード例 #1
0
 public static bool canCubeBeMouseClicked(ushort ID, ref CubeData data) //hydroponics bays are the same ID as canopies
 {
     if (ID == eCubeTypes.TNTButNowGrass)
     {
         return(false);
     }
     if (ID == eCubeTypes.Hydroponics && data.mValue == 1)
     {
         return(false);
     }
     if (CubeHelper.IsCustom(ID) || CubeHelper.HasObject(ID) || CubeHelper.HasEmbeddedObject(ID))
     {
         return(true);
     }
     return(CubeHelper.IsCubeSolid(ID));
 }
コード例 #2
0
        public void Update(BlockSurveyor Surveyor)
        {
            var from  = this.StartBlock + Direction.Up().Shift *this.LastCheckedPosition;
            var to    = from + Direction.Up().Shift *CheckChunk;
            var clear = new GridBox(new Box(from, to)).Blocks()
                        .Select(b => CubeHelper.IsCubeSolid(Surveyor.Look().At(b).Block()?.Type ?? 1))
                        .NoneTrue();

            if (clear)
            {
                this.LastCheckedPosition = (this.LastCheckedPosition + CheckChunk) % ClearHeight;
                if (this.LastCheckedPosition == 0)
                {
                    this.Clear = true;
                }
            }
            else
            {
                this.Clear = false;
                this.LastCheckedPosition = 0;
            }
        }
コード例 #3
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++;
            }
        }