Exemple #1
0
        private void RunUpdate(ref SensorDetectingNode node)
        {
            var sensor = node.Sensor;

            sensor.DetectedCells.Clear();
            var start = node.Position.Position;

            sensor.LastDetectedCenter = start;
            var fwd = node.Tr.ForwardDirection2D();
            var ls  = World.Get <LineOfSightSystem>();

            for (int i = 0; i < DirectionsExtensions.Length2D; i++)
            {
                var dir            = (Directions)i;
                var maxRowDistance = dir == fwd ? sensor.MaxVisionDistance : sensor.MaxHearDistance;
                var adjacent       = dir.Adjacent();
                ShadowFloodFill.CheckRow(
                    ref sensor.DetectedCells, start, start,
                    maxRowDistance, new[] { adjacent[0].ToPoint3(), adjacent[1].ToPoint3() }, dir.ToPoint3());
            }
            for (int i = 0; i < _occupyNodes.Max; i++)
            {
                if (_occupyNodes.IsInvalid(i))
                {
                    continue;
                }
                var visible = _occupyNodes[i];
                if (visible.Entity == node.Entity)
                {
                    continue;
                }
                if (!sensor.DetectedCells.Contains(visible.Position))
                {
                    continue;
                }
                var isVision = true;
                if (CheckVision)
                {
                    ls.CanSeeOrHear(node.Entity, visible.Entity, out isVision);
                }
                sensor.AddWatch(visible.Entity, isVision);
            }
            for (int w = sensor.WatchTargets.Count - 1; w >= 0; w--)
            {
                if (sensor.WatchTargets[w].Target == null)
                {
                    sensor.RemoveWatch(sensor.WatchTargets[w]);
                    continue;
                }
                sensor.WatchTargets[w].LastSensedTurnCount++;
                if (sensor.WatchTargets[w].LastSensedTurnCount > MaxTurnsNpcVisible)
                {
                    sensor.RemoveWatch(sensor.WatchTargets[w]);
                }
            }
        }
Exemple #2
0
        public SensorSystem()
        {
            NodeFilter <SensorDetectingNode> .Setup(SensorDetectingNode.GetTypes());

            _sensorNodes = EntityController.GetNodeList <SensorDetectingNode>();
            NodeFilter <UnitySensorNode> .Setup(UnitySensorNode.GetTypes());

            _unitySensorNodes = EntityController.GetNodeList <UnitySensorNode>();
            EntityController.RegisterReceiver(new EventReceiverFilter(this, new[] {
                typeof(SensorTargetsComponent)
            }));
        }
Exemple #3
0
 public SensorSystem()
 {
     NodeFilter <SensorDetectingNode> .New(SensorDetectingNode.GetTypes());
 }