Exemplo n.º 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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
0
        public virtual IEnumerable <IActorPreview> RenderPreview(ActorPreviewInitializer init)
        {
            var body             = init.Actor.Traits.Get <BodyOrientationInfo>();
            var sequenceProvider = init.World.Map.SequenceProvider;
            var image            = Image ?? init.Actor.Name;
            var facings          = body.QuantizedFacings == -1 ? init.Actor.Traits.Get <IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
            var palette          = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));

            var facing      = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 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, this.Scale, this.LightPitch,
                                          this.LightYaw, this.LightAmbientColor, this.LightDiffuseColor, body.CameraPitch,
                                          palette, init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette("shadow")));
        }
Exemplo n.º 14
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));
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
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));
        }
Exemplo n.º 17
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 ifacing = init.Actor.TraitInfoOrDefault <IFacingInfo>();
            var facing  = ifacing != null?init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing() : 0;

            var orientation = WRot.FromFacing(facing);
            var components  = init.Actor.TraitInfos <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)));
        }