Пример #1
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            var body = init.Actor.Traits.Get <BodyOrientationInfo>();
            var t    = init.Actor.Traits.WithInterface <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var ifacing    = init.Actor.Traits.GetOrDefault <IFacingInfo>();
            var bodyFacing = ifacing != null?init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing() : 0;

            var turretFacing = init.Contains <TurretFacingInit>() ? init.Get <TurretFacingInit, int>() : t.InitialFacing;

            var anim = new Animation(init.World, image, () => turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(bodyFacing)), facings);
            var offset      = body.LocalToWorld(t.Offset.Rotate(orientation));

            yield return(new SpriteActorPreview(anim, offset, -(offset.Y + offset.Z) + 1, p, rs.Scale));
        }
Пример #2
0
        public IEnumerable <IActorPreview> RenderPreview(ActorPreviewInitializer init)
        {
            var sequenceProvider = init.World.Map.Rules.Sequences;
            var faction          = init.Get <FactionInit, string>();
            var ownerName        = init.Get <OwnerInit>().PlayerName;
            var image            = GetImage(init.Actor, sequenceProvider, faction);
            var palette          = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);

            var facings = 0;
            var body    = init.Actor.TraitInfoOrDefault <BodyOrientationInfo>();

            if (body != null)
            {
                facings = body.QuantizedFacings;

                if (facings == -1)
                {
                    var qbo = init.Actor.TraitInfoOrDefault <IQuantizeBodyOrientationInfo>();
                    facings = qbo != null?qbo.QuantizedBodyFacings(init.Actor, sequenceProvider, faction) : 1;
                }
            }

            foreach (var spi in init.Actor.TraitInfos <IRenderActorPreviewSpritesInfo>())
            {
                foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
                {
                    yield return(preview);
                }
            }
        }
Пример #3
0
		public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
		{
			var sequenceProvider = init.World.Map.SequenceProvider;
			var faction = init.Get<FactionInit, string>();
			var ownerName = init.Get<OwnerInit>().PlayerName;
			var image = GetImage(init.Actor, sequenceProvider, faction);
			var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);

			var facings = 0;
			var body = init.Actor.TraitInfoOrDefault<BodyOrientationInfo>();
			if (body != null)
			{
				facings = body.QuantizedFacings;

				if (facings == -1)
				{
					var qbo = init.Actor.TraitInfoOrDefault<IQuantizeBodyOrientationInfo>();
					facings = qbo != null ? qbo.QuantizedBodyFacings(init.Actor, sequenceProvider, faction) : 1;
				}
			}

			foreach (var spi in init.Actor.TraitInfos<IRenderActorPreviewSpritesInfo>())
				foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
					yield return preview;
		}
Пример #4
0
        public override IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var adjacent = 0;

            if (init.Contains <RuntimeNeighbourInit>())
            {
                var location = CPos.Zero;
                if (init.Contains <LocationInit>())
                {
                    location = init.Get <LocationInit, CPos>();
                }

                var neighbours = init.Get <RuntimeNeighbourInit, Dictionary <CPos, string[]> >();
                foreach (var kv in neighbours)
                {
                    var haveNeighbour = false;
                    foreach (var n in kv.Value)
                    {
                        var rb = init.World.Map.Rules.Actors[n].TraitInfos <IWallConnectorInfo>().FirstOrDefault(Exts.IsTraitEnabled);
                        if (rb != null && rb.GetWallConnectionType() == Type)
                        {
                            haveNeighbour = true;
                            break;
                        }
                    }

                    if (!haveNeighbour)
                    {
                        continue;
                    }

                    if (kv.Key == location + new CVec(0, -1))
                    {
                        adjacent |= 1;
                    }
                    else if (kv.Key == location + new CVec(+1, 0))
                    {
                        adjacent |= 2;
                    }
                    else if (kv.Key == location + new CVec(0, +1))
                    {
                        adjacent |= 4;
                    }
                    else if (kv.Key == location + new CVec(-1, 0))
                    {
                        adjacent |= 8;
                    }
                }
            }

            var anim = new Animation(init.World, image, () => 0);

            anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => adjacent);

            yield return(new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale));
        }
Пример #5
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (init.Contains <HideBibPreviewInit>() && init.Get <HideBibPreviewInit, bool>())
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var bi = init.Actor.TraitInfo <BuildingInfo>();

            var rows         = HasMinibib ? 1 : 2;
            var width        = bi.Dimensions.X;
            var bibOffset    = bi.Dimensions.Y - rows;
            var centerOffset = bi.CenterOffset(init.World);
            var map          = init.World.Map;
            var location     = CPos.Zero;

            if (init.Contains <LocationInit>())
            {
                location = init.Get <LocationInit, CPos>();
            }

            for (var i = 0; i < rows * width; i++)
            {
                var index      = i;
                var anim       = new Animation(init.World, image);
                var cellOffset = new CVec(i % width, i / width + bibOffset);
                var cell       = location + cellOffset;

                // Some mods may define terrain-specific bibs
                var sequence = Sequence;
                if (map.Tiles.Contains(cell))
                {
                    var terrain      = map.GetTerrainInfo(cell).Type;
                    var testSequence = Sequence + "-" + terrain;
                    if (anim.HasSequence(testSequence))
                    {
                        sequence = testSequence;
                    }
                }

                anim.PlayFetchIndex(sequence, () => index);
                anim.IsDecoration = true;

                // Z-order is one set to the top of the footprint
                var offset = map.CenterOfCell(cell) - map.CenterOfCell(location) - centerOffset;
                yield return(new SpriteActorPreview(anim, () => offset, () => - (offset.Y + centerOffset.Y + 512), p, rs.Scale));
            }
        }
Пример #6
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            if (image == null)
            {
                yield break;
            }

            // For this, image must not be null
            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var anim = new Animation(init.World, image);

            anim.PlayThen(OpeningSequence, () => anim.PlayRepeating(Sequence));

            var body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            var facing      = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
            var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
            var offset      = body.LocalToWorld(Offset.Rotate(orientation));

            yield return(new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale));
        }
Пример #7
0
        public virtual IEnumerable <IActorPreview> RenderPreview(ActorPreviewInitializer init)
        {
            var body             = init.Actor.TraitInfo <BodyOrientationInfo>();
            var faction          = init.Get <FactionInit, string>();
            var ownerName        = init.Get <OwnerInit>().PlayerName;
            var sequenceProvider = init.World.Map.Rules.Sequences;
            var image            = Image ?? init.Actor.Name;
            var facings          = body.QuantizedFacings == -1 ? init.Actor.TraitInfo <IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, faction) :
                                   body.QuantizedFacings;

            var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);

            var components = init.Actor.TraitInfos <IRenderActorPreviewVoxelsInfo>().SelectMany(rvpi => rvpi.RenderPreviewVoxels(init, this, image, init.GetOrientation(), facings, palette)).ToArray();

            yield return(new ModelPreview(components, WVec.Zero, 0, Scale, LightPitch, LightYaw, LightAmbientColor, LightDiffuseColor, body.CameraPitch, palette, init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette(ShadowPalette)));
        }
Пример #8
0
        public IEnumerable <IActorPreview> RenderPreview(ActorPreviewInitializer init)
        {
            var sequenceProvider = init.World.Map.SequenceProvider;
            var race             = init.Contains <RaceInit>() ? init.Get <RaceInit, string>() : init.Owner.Country.Race;
            var image            = GetImage(init.Actor, sequenceProvider, race);
            var palette          = init.WorldRenderer.Palette(Palette ?? PlayerPalette + init.Owner.InternalName);

            var facings = 0;
            var body    = init.Actor.Traits.GetOrDefault <BodyOrientationInfo>();

            if (body != null)
            {
                facings = body.QuantizedFacings == -1 ?
                          init.Actor.Traits.Get <IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, init.Owner.Country.Race) :
                          body.QuantizedFacings;
            }

            foreach (var spi in init.Actor.Traits.WithInterface <IRenderActorPreviewSpritesInfo>())
            {
                foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
                {
                    yield return(preview);
                }
            }
        }
Пример #9
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p)
        {
            if (!this.EnabledByDefault)
            {
                yield break;
            }

            var body         = init.Actor.TraitInfoOrDefault <BodyOrientationInfo>();
            var turretedInfo = init.Actor.TraitInfos <TurretedInfo>().FirstOrDefault(tt => tt.Turret == this.Turret);

            if (turretedInfo == null)
            {
                yield break;
            }

            var facing = init.GetFacing();
            var offset = new Func <WVec>(() => body.LocalToWorld(turretedInfo.Offset.Rotate(body.QuantizeOrientation(WRot.FromYaw(facing()), facings))));

            var bodyAnim = new Animation(init.World, image, init.GetFacing());

            bodyAnim.PlayRepeating(RenderSprites.NormalizeSequence(bodyAnim, init.GetDamageState(), "idle"));

            if (bodyAnim.CurrentSequence is OffsetsSpriteSequence bodySequence && bodySequence.EmbeddedOffsets.TryGetValue(bodyAnim.Image, out var imageOffset))
            {
                var point = imageOffset.FirstOrDefault(p1 => p1.Id == 0);

                if (point != null)
                {
                    offset = () => new(point.X * 32, point.Y * 32, 0);
                }
            }

            if (this.IsPlayerPalette)
            {
                p = init.WorldRenderer.Palette(this.Palette + init.Get <OwnerInit>().InternalName);
            }
            else if (this.Palette != null)
            {
                p = init.WorldRenderer.Palette(this.Palette);
            }

            var turretFacing = turretedInfo.WorldFacingFromInit(init);
            var anim         = new Animation(init.World, image, turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), this.Sequence));

            yield return(new SpriteActorPreview(
                             anim,
                             offset,
                             () =>
            {
                var tmpOffset = offset();

                return -(tmpOffset.Y + tmpOffset.Z) + 1;
            },
                             p
                             ));
        }
Пример #10
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            if (image == null)
            {
                yield break;
            }

            // For this, image must not be null
            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            Func <int> facing;

            if (init.Contains <DynamicFacingInit>())
            {
                facing = init.Get <DynamicFacingInit, Func <int> >();
            }
            else
            {
                var f = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
                facing = () => f;
            }

            var anim = new Animation(init.World, image);

            anim.PlayThen(OpeningSequence, () => anim.PlayRepeating(Sequence));

            var         body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(tmpOffset.Y + tmpOffset.Z + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
        }
Пример #11
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var body = init.Actor.TraitInfo <BodyOrientationInfo>();
            var t    = init.Actor.TraitInfos <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var bodyAnim = new Animation(init.World, image, init.GetFacing());

            bodyAnim.PlayRepeating(RenderSprites.NormalizeSequence(bodyAnim, init.GetDamageState(), "idle"));
            var         bodySequence = bodyAnim.CurrentSequence as OffsetsSpriteSequence;
            Func <WVec> offset       = null;

            if (bodySequence != null && bodySequence.EmbeddedOffsets.ContainsKey(bodyAnim.Image) && bodySequence.EmbeddedOffsets[bodyAnim.Image] != null)
            {
                var point = bodySequence.EmbeddedOffsets[bodyAnim.Image].FirstOrDefault(p1 => p1.Id == 0);

                if (point != null)
                {
                    offset = () => new WVec(point.X * 32, point.Y * 32, 0);
                }
            }

            var turretFacing = t.WorldFacingFromInit(init);
            var anim         = new Animation(init.World, image, turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            if (offset == null)
            {
                var         facing      = init.GetFacing();
                Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
                offset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
            }

            Func <int> zOffset = () =>
            {
                var tmpOffset = offset();
                return(-(tmpOffset.Y + tmpOffset.Z) + 1);
            };

            if (IsPlayerPalette)
            {
                p = init.WorldRenderer.Palette(Palette + init.Get <OwnerInit>().InternalName);
            }
            else if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            yield return(new SpriteActorPreview(anim, offset, zOffset, p));
        }
Пример #12
0
        public virtual IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var ifacing = init.Actor.Traits.GetOrDefault <IFacingInfo>();
            var facing  = ifacing != null?init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing() : 0;

            var anim = new Animation(init.World, image, () => facing);

            anim.PlayRepeating("idle");
            yield return(new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale));
        }
Пример #13
0
        public IEnumerable <VoxelAnimation> RenderPreviewVoxels(
            ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func <WRot> orientation, int facings, PaletteReference p)
        {
            var voxel = VoxelProvider.GetVoxel(image, Sequence);
            var body  = init.Actor.TraitInfo <BodyOrientationInfo>();
            var frame = init.Contains <BodyAnimationFrameInit>() ? init.Get <BodyAnimationFrameInit, uint>() : 0;

            yield return(new VoxelAnimation(voxel, () => WVec.Zero,
                                            () => new[] { body.QuantizeOrientation(orientation(), facings) },
                                            () => false, () => frame, ShowShadow));
        }
Пример #14
0
        public new IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            var        idleImage = !string.IsNullOrEmpty(Image) ? Image : image;
            Func <int> facing;

            if (init.Contains <DynamicFacingInit>())
            {
                facing = init.Get <DynamicFacingInit, Func <int> >();
            }
            else
            {
                var f = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
                facing = () => f;
            }

            var anim = new Animation(init.World, idleImage, facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var         body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(tmpOffset.Y + tmpOffset.Z + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p, rs.Scale));
        }
Пример #15
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var body   = init.Actor.Traits.Get <BodyOrientationInfo>();
            var facing = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;
            var anim   = new Animation(init.World, image, () => facing);

            anim.PlayRepeating(Sequence);

            var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
            var offset      = body.LocalToWorld(Offset.Rotate(orientation));

            yield return(new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale));
        }
Пример #16
0
        public virtual IEnumerable <IActorPreview> RenderPreview(ActorPreviewInitializer init)
        {
            var body             = init.Actor.Traits.Get <BodyOrientationInfo>();
            var race             = init.Get <RaceInit, string>();
            var ownerName        = init.Get <OwnerInit>().PlayerName;
            var sequenceProvider = init.World.Map.SequenceProvider;
            var image            = Image ?? init.Actor.Name;
            var facings          = body.QuantizedFacings == -1 ?
                                   init.Actor.Traits.Get <IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, race) :
                                   body.QuantizedFacings;
            var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);

            var ifacing = init.Actor.Traits.GetOrDefault <IFacingInfo>();
            var facing  = ifacing != null?init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing() : 0;

            var orientation = WRot.FromFacing(facing);
            var components  = init.Actor.Traits.WithInterface <IRenderActorPreviewVoxelsInfo>()
                              .SelectMany(rvpi => rvpi.RenderPreviewVoxels(init, this, image, orientation, facings, palette))
                              .ToArray();

            yield return(new VoxelPreview(components, WVec.Zero, 0, Scale, LightPitch,
                                          LightYaw, LightAmbientColor, LightDiffuseColor, body.CameraPitch,
                                          palette, init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette(ShadowPalette)));
        }
Пример #17
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var facing  = 0;
            var ifacing = init.Actor.TraitInfoOrDefault <IFacingInfo>();

            if (ifacing != null)
            {
                facing = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing();
            }

            var anim = new Animation(init.World, image, () => facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First()));
            yield return(new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale));
        }
Пример #18
0
        public IEnumerable <VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
        {
            var body = init.Actor.Traits.Get <BodyOrientationInfo>();
            var t    = init.Actor.Traits.WithInterface <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var voxel        = VoxelProvider.GetVoxel(image, Sequence);
            var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));

            var turretFacing          = init.Contains <TurretFacingInit>() ? init.Get <TurretFacingInit, int>() : t.InitialFacing;
            var turretBodyOrientation = new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw);
            var turretOrientation     = new[] { turretBodyOrientation, body.QuantizeOrientation(orientation, facings) };

            yield return(new VoxelAnimation(voxel, () => turretOffset, () => turretOrientation, () => false, () => 0));
        }
Пример #19
0
        public IEnumerable <VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
        {
            var sequence = LandSequence;

            if (init.Contains <LocationInit>())
            {
                var location = init.Get <LocationInit>().Value(init.World);
                var onWater  = init.World.Map.GetTerrainInfo(location).IsWater;
                sequence = onWater ? WaterSequence : LandSequence;
            }

            var body  = init.Actor.TraitInfo <BodyOrientationInfo>();
            var voxel = VoxelProvider.GetVoxel(image, sequence);

            yield return(new VoxelAnimation(voxel, () => WVec.Zero,
                                            () => new[] { body.QuantizeOrientation(orientation, facings) },
                                            () => false, () => 0));
        }
Пример #20
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            if (Palette != null)
            {
                var ownerName = init.Get <OwnerInit>().InternalName;
                p = init.WorldRenderer.Palette(IsPlayerPalette ? Palette + ownerName : Palette);
            }

            Func <WAngle> facing;
            var           dynamicfacingInit = init.GetOrDefault <DynamicFacingInit>();

            if (dynamicfacingInit != null)
            {
                facing = dynamicfacingInit.Value;
            }
            else
            {
                var f = init.GetValue <FacingInit, WAngle>(WAngle.Zero);
                facing = () => f;
            }

            var anim = new Animation(init.World, Image ?? image, facing)
            {
                IsDecoration = IsDecoration
            };

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var         body        = init.Actor.TraitInfo <BodyOrientationInfo>();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(tmpOffset.Y + tmpOffset.Z + 1);
            };

            yield return(new SpriteActorPreview(anim, offset, zOffset, p));
        }
Пример #21
0
        public override IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var t   = init.Actor.TraitInfos <TurretedInfo>().FirstOrDefault();
            var wsb = init.Actor.TraitInfos <WithSpriteBodyInfo>().FirstOrDefault();

            // Show the correct turret facing
            var facing = init.Contains <TurretFacingInit>() ? init.Get <TurretFacingInit>().Value(init.World) : t.InitialFacing;

            var anim = new Animation(init.World, image, () => facing);

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));

            yield return(new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale));
        }
Пример #22
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var anim = new Animation(init.World, image, init.GetFacing());

            anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First()));

            if (IsPlayerPalette)
            {
                p = init.WorldRenderer.Palette(Palette + init.Get <OwnerInit>().InternalName);
            }
            else if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            yield return(new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale));
        }
Пример #23
0
        public IEnumerable <VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            var body     = init.Actor.TraitInfo <BodyOrientationInfo>();
            var armament = init.Actor.TraitInfos <ArmamentInfo>()
                           .First(a => a.Name == Armament);
            var t = init.Actor.TraitInfos <TurretedInfo>()
                    .First(tt => tt.Turret == armament.Turret);

            var voxel = VoxelProvider.GetVoxel(image, Sequence);

            var turretFacing      = init.Contains <TurretFacingInit>() ? init.Get <TurretFacingInit, int>() : t.InitialFacing;
            var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw), facings);
            var turretOffset      = body.LocalToWorld(t.Offset.Rotate(orientation));

            yield return(new VoxelAnimation(voxel, () => turretOffset, () => new[] { turretOrientation, orientation },
                                            () => false, () => 0));
        }
Пример #24
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p)
        {
            if (!EnabledByDefault)
            {
                yield break;
            }

            var body = init.Actor.TraitInfo <BodyOrientationInfo>();
            var t    = init.Actor.TraitInfos <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var turretFacing = t.WorldFacingFromInit(init);
            var anim         = new Animation(init.World, image, turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var         facing      = init.GetFacing();
            Func <WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
            Func <WVec> offset      = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
            Func <int>  zOffset     = () =>
            {
                var tmpOffset = offset();
                return(-(tmpOffset.Y + tmpOffset.Z) + 1);
            };

            if (IsPlayerPalette)
            {
                p = init.WorldRenderer.Palette(Palette + init.Get <OwnerInit>().InternalName);
            }
            else if (Palette != null)
            {
                p = init.WorldRenderer.Palette(Palette);
            }

            yield return(new SpriteActorPreview(anim, offset, zOffset, p));
        }