Ejemplo n.º 1
0
        void ITick.Tick(Actor self)
        {
            if (!anyCellTouched)
            {
                return;
            }

            anyCellTouched = false;

            if (OnShroudChanged == null)
            {
                return;
            }

            foreach (var puv in map.ProjectedCells)
            {
                var index = touched.Index(puv);
                if (!touched[index])
                {
                    continue;
                }

                touched[index] = false;

                var type = ShroudCellType.Shroud;

                if (explored[index])
                {
                    var count = visibleCount[index];
                    if (!shroudGenerationEnabled || count > 0 || generatedShroudCount[index] == 0)
                    {
                        if (passiveVisibilityEnabled)
                        {
                            count += passiveVisibleCount[index];
                        }

                        type = count > 0 ? ShroudCellType.Visible : ShroudCellType.Fog;
                    }
                }

                var oldResolvedType = resolvedType[index];
                if (type != oldResolvedType)
                {
                    resolvedType[index] = type;
                    OnShroudChanged(puv);
                }
            }

            Hash = Sync.HashPlayer(self.Owner) + self.World.WorldTick;
        }
Ejemplo n.º 2
0
        public void AddSource(object key, SourceType type, PPos[] projectedCells)
        {
            if (sources.ContainsKey(key))
            {
                throw new InvalidOperationException("Attempting to add duplicate shroud source");
            }

            sources[key] = new ShroudSource(type, projectedCells);

            foreach (var puv in projectedCells)
            {
                // Force cells outside the visible bounds invisible
                if (!map.Contains(puv))
                {
                    continue;
                }

                var index = touched.Index(puv);
                touched[index] = true;
                anyCellTouched = true;
                switch (type)
                {
                case SourceType.PassiveVisibility:
                    passiveVisibilityEnabled = true;
                    passiveVisibleCount[index]++;
                    explored[index] = true;
                    break;

                case SourceType.Visibility:
                    visibleCount[index]++;
                    explored[index] = true;
                    break;

                case SourceType.Shroud:
                    shroudGenerationEnabled = true;
                    generatedShroudCount[index]++;
                    break;
                }
            }
        }