Esempio n. 1
0
            void UpdateCenterLocation(Actor self, Mobile mobile)
            {
                //Avoid division through zero
                if (MoveFractionTotal != 0)
                {
                    WPos pos = WPos.Zero;
                    if (EnableArc)
                    {
                        var angle  = WAngle.Lerp(ArcFromAngle, ArcToAngle, moveFraction, MoveFractionTotal);
                        var length = Int2.Lerp(ArcFromLength, ArcToLength, moveFraction, MoveFractionTotal);
                        var height = Int2.Lerp(From.Z, To.Z, moveFraction, MoveFractionTotal);
                        pos = ArcCenter + new WVec(0, length, length).Rotate(WRot.FromYaw(angle));
                    }
                    else
                    {
                        pos = WPos.Lerp(From, To, moveFraction, MoveFractionTotal);
                    }

                    mobile.SetVisualPosition(self, pos);
                }
                else
                {
                    mobile.SetVisualPosition(self, To);
                }

                if (moveFraction >= MoveFractionTotal)
                {
                    mobile.Facing = ToFacing & 0xFF;
                }
                else
                {
                    mobile.Facing = Int2.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal) & 0xFF;
                }
            }
Esempio n. 2
0
        public void LoadPalettes(WorldRenderer wr)
        {
            Func <int, uint> makeColor = i =>
            {
                if (i < 128)
                {
                    return((uint)(Int2.Lerp(255, 0, i, 127) << 24));
                }
                return(0);
            };

            wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => makeColor(i))));
        }
Esempio n. 3
0
        int GetFalloff(int distance)
        {
            var inner = info.Range[0].Length;

            for (var i = 1; i < info.Range.Length; i++)
            {
                var outer = info.Range[i].Length;
                if (outer > distance)
                {
                    return(Int2.Lerp(info.Falloff[i - 1], info.Falloff[i], distance - inner, outer - inner));
                }

                inner = outer;
            }
            return(0);
        }
Esempio n. 4
0
        protected virtual void UpdateRenderedSprite(CPos cell)
        {
            var t = RenderContent[cell];

            if (t.Density > 0)
            {
                var sprites = t.Type.Variants[t.Variant];
                var frame   = Int2.Lerp(0, sprites.Length - 1, t.Density, t.Type.Info.MaxDensity);
                t.Sprite = sprites[frame];
            }
            else
            {
                t.Sprite = null;
            }

            RenderContent[cell] = t;
        }
Esempio n. 5
0
        int GetDamageFalloff(int distance)
        {
            var inner = Range[0].Length;

            for (var i = 1; i < Range.Length; i++)
            {
                var outer = Range[i].Length;
                if (outer > distance)
                {
                    return(Int2.Lerp(Falloff[i - 1], Falloff[i], distance - inner, outer - inner));
                }

                inner = outer;
            }

            return(0);
        }
Esempio n. 6
0
 int GetGateFrame()
 {
     return(Int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition));
 }
Esempio n. 7
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var resources = w.WorldActor.TraitsImplementing <ResourceType>().ToDictionary(r => r.Info.ResourceType, r => r);

            //Build the sprite layer dictionary for rendering resources
            //All resources that have the same palette must also share a sheet and blend mode
            foreach (var r in resources)
            {
                var layer = spriteLayers.GetOrAdd(r.Value.Palette, pal =>
                {
                    var first = r.Value.Variants.First().Value.First();

                    return(new TerrainSpriteLayer(w, wr, first.Sheet, first.BlendMode, pal, wr.World.Type != WorldT.Editor));
                });

                //Validate that sprites are compatible with this layer
                var sheet = layer.Sheet;
                if (r.Value.Variants.Any(kv => kv.Value.Any(s => s.Sheet != sheet)))
                {
                    throw new InvalidDataException("Resource sprites span multiple sheets,Try loading their sequences earlier.");
                }

                var blendMode = layer.BlendMode;
                if (r.Value.Variants.Any(kv => kv.Value.Any(s => s.BlendMode != blendMode)))
                {
                    throw new InvalidDataException("Resource sprites specify different blend modes.Try using different palettes for resource types that use different blend modes.");
                }
            }

            foreach (var cell in w.Map.AllCells)
            {
                ResourceType t;
                if (!resources.TryGetValue(w.Map.Resources[cell].Type, out t))
                {
                    continue;
                }

                if (!AllowResourceAt(t, cell))
                {
                    continue;
                }

                Content[cell] = CreateResourceCell(t, cell);
            }

            foreach (var cell in w.Map.AllCells)
            {
                var type = Content[cell].Type;
                if (type != null)
                {
                    //Set initial density based on the number of neighboring resources
                    //Adjacent includes the current cell,so is always >=1;
                    var adjacent = GetAdjacentCellsWith(type, cell);
                    var density  = Int2.Lerp(0, type.Info.MaxDensity, adjacent, 9);
                    var temp     = Content[cell];
                    temp.Density = Math.Max(density, 1);

                    //Initialize the RenderContent with the initial map state
                    //because the shroud may not be enabled;
                    RenderContent[cell] = Content[cell] = temp;
                    UpdateRenderedSprite(cell);
                }
            }
        }