CenterOffset() public static method

public static CenterOffset ( World w, BuildingInfo buildingInfo ) : WVec
w World
buildingInfo BuildingInfo
return WVec
Ejemplo n.º 1
0
        public void AddedToWorld(Actor self)
        {
            var width        = bi.Dimensions.X;
            var bibOffset    = bi.Dimensions.Y - 1;
            var centerOffset = FootprintUtils.CenterOffset(self.World, bi);
            var location     = self.Location;
            var rows         = info.HasMinibib ? 1 : 2;
            var map          = self.World.Map;

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

                // Some mods may define terrain-specific bibs
                var terrain      = map.GetTerrainInfo(cell).Type;
                var testSequence = info.Sequence + "-" + terrain;
                var sequence     = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
                anim.PlayFetchIndex(sequence, () => index);
                anim.IsDecoration = true;

                // Z-order is one set to the top of the footprint
                var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset;
                var awo    = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
                anims.Add(awo);
                rs.Add(awo, info.Palette);
            }
        }
Ejemplo n.º 2
0
        WPos PreviewPosition(World world, TypeDictionary init)
        {
            if (init.Contains <CenterPositionInit>())
            {
                return(init.Get <CenterPositionInit>().Value(world));
            }

            if (init.Contains <LocationInit>())
            {
                var cell   = init.Get <LocationInit>().Value(world);
                var offset = WVec.Zero;

                var subCellInit = actor.InitDict.GetOrDefault <SubCellInit>();
                var subCell     = subCellInit != null?subCellInit.Value(worldRenderer.World) : SubCell.Any;

                var buildingInfo = Info.TraitInfoOrDefault <BuildingInfo>();
                if (buildingInfo != null)
                {
                    offset = FootprintUtils.CenterOffset(world, buildingInfo);
                }

                return(world.Map.CenterOfSubCell(cell, subCell) + offset);
            }
            else
            {
                throw new InvalidDataException("Actor {0} must define Location or CenterPosition".F(ID));
            }
        }
Ejemplo n.º 3
0
        IRenderable[] TemplateRenderables(WorldRenderer wr, PaletteReference palette, ushort template)
        {
            var offset = FootprintUtils.CenterOffset(self.World, building).Y + 1024;

            return(footprint.Select(c => (IRenderable)(new SpriteRenderable(
                                                           wr.Theater.TileSprite(new TerrainTile(template, c.Value)),
                                                           wr.World.Map.CenterOfCell(c.Key), WVec.Zero, -offset, palette, 1f, true))).ToArray());
        }
Ejemplo n.º 4
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            var anim = new Animation(init.World, image, () => 0);

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

            var bi     = init.Actor.TraitInfo <BuildingInfo>();
            var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512;             // Additional 512 units move from center -> top of cell

            yield return(new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale));
        }
Ejemplo n.º 5
0
        public Building(ActorInitializer init, BuildingInfo info)
        {
            this.self    = init.Self;
            this.topLeft = init.Get <LocationInit, CPos>();
            this.Info    = info;

            occupiedCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft)
                            .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();

            CenterPosition    = init.World.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.World, Info);
            SkipMakeAnimation = init.Contains <SkipMakeAnimsInit>();
        }
Ejemplo n.º 6
0
        public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info)
            : base(init, info)
        {
            roof = new Animation(init.World, GetImage(init.Self));
            var bi = init.Self.Info.Traits.Get <BuildingInfo>();

            // Additional 512 units move from center -> top of cell
            var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512;

            Add("roof", new AnimationWithOffset(roof, null,
                                                () => !buildComplete, offset));
        }
Ejemplo n.º 7
0
        public WithProductionDoorOverlay(Actor self, WithProductionDoorOverlayInfo info)
        {
            var renderSprites = self.Trait <RenderSprites>();

            door = new Animation(self.World, renderSprites.GetImage(self));
            door.PlayFetchDirection(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence),
                                    () => desiredFrame - door.CurrentFrame);

            var buildingInfo = self.Info.TraitInfo <BuildingInfo>();

            var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512;

            renderSprites.Add(new AnimationWithOffset(door, null, () => !buildComplete, offset));
        }
Ejemplo n.º 8
0
        public override IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            foreach (var orig in base.RenderPreviewSprites(init, rs, image, facings, p))
            {
                yield return(orig);
            }

            // Show additional roof overlay
            var anim = new Animation(init.World, image, () => 0);

            anim.PlayRepeating("idle-top");

            var bi     = init.Actor.Traits.Get <BuildingInfo>();
            var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512;

            yield return(new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale));
        }
Ejemplo n.º 9
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 width        = bi.Dimensions.X;
            var bibOffset    = bi.Dimensions.Y - 1;
            var centerOffset = FootprintUtils.CenterOffset(init.World, bi);
            var rows         = HasMinibib ? 1 : 2;
            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 terrain      = map.GetTerrainInfo(cell).Type;
                var testSequence = Sequence + "-" + terrain;
                var sequence     = anim.HasSequence(testSequence) ? testSequence : Sequence;
                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));
            }
        }
Ejemplo n.º 10
0
        public Actor FindBaseProvider(World world, Player p, CPos topLeft)
        {
            var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this);

            foreach (var bp in world.ActorsWithTrait <BaseProvider>())
            {
                var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
                if (!validOwner || !bp.Trait.Ready())
                {
                    continue;
                }

                // Range is counted from the center of the actor, not from each cell.
                var target = Target.FromPos(bp.Actor.CenterPosition);
                if (target.IsInRange(center, WRange.FromCells(bp.Trait.Info.Range)))
                {
                    return(bp.Actor);
                }
            }

            return(null);
        }