Beispiel #1
0
        public void Render(WorldRenderer wr)
        {
            if (!hasSetupPalettes)
            {
                hasSetupPalettes = true;
                foreach (var rt in world.WorldActor.TraitsImplementing <ResourceType>())
                {
                    rt.info.PaletteIndex = wr.GetPaletteIndex(rt.info.Palette);
                }
            }

            var clip = Game.viewport.WorldBounds(world);

            for (int x = clip.Left; x < clip.Right; x++)
            {
                for (int y = clip.Top; y < clip.Bottom; y++)
                {
                    if (!world.LocalShroud.IsExplored(new CPos(x, y)))
                    {
                        continue;
                    }

                    var c = content[x, y];
                    if (c.image != null)
                    {
                        c.image[c.density].DrawAt(
                            new CPos(x, y).ToPPos().ToFloat2(),
                            c.type.info.PaletteIndex);
                    }
                }
            }
        }
        public void RenderBeforeWorld(WorldRenderer wr, World world)
        {
            var position = Game.viewport.ViewToWorld(Viewport.LastMousePos);
            var topLeft  = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo);

            var actorInfo = Rules.Info[Building];

            foreach (var dec in actorInfo.Traits.WithInterface <IPlaceBuildingDecoration>())
            {
                dec.Render(wr, world, actorInfo, Traits.Util.CenterOfCell(position));                   /* hack hack */
            }
            var cells = new Dictionary <CPos, bool>();

            // Linebuild for walls.
            // Assumes a 1x1 footprint; weird things will happen for other footprints
            if (Rules.Info[Building].Traits.Contains <LineBuildInfo>())
            {
                foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, Building, BuildingInfo))
                {
                    cells.Add(t, BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, t));
                }
            }
            else
            {
                foreach (var r in Preview)
                {
                    r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos,
                                    wr.GetPaletteIndex(r.Palette),
                                    r.Scale * r.Sprite.size);
                }

                var res           = world.WorldActor.Trait <ResourceLayer>();
                var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
                foreach (var t in FootprintUtils.Tiles(Building, BuildingInfo, topLeft))
                {
                    cells.Add(t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null);
                }
            }

            foreach (var c in cells)
            {
                (c.Value ? buildOk : buildBlocked).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain");
            }
        }
Beispiel #3
0
            public void RenderBeforeWorld(WorldRenderer wr, World world)
            {
                var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();

                // Source tiles
                foreach (var t in world.FindTilesInCircle(sourceLocation, range))
                {
                    sourceTile.DrawAt(wr, Game.CellSize * t, "terrain");
                }

                // Destination tiles
                foreach (var t in world.FindTilesInCircle(xy, range))
                {
                    sourceTile.DrawAt(wr, Game.CellSize * t, "terrain");
                }

                // Unit previews
                foreach (var unit in power.UnitsInRange(sourceLocation))
                {
                    var targetCell = unit.Location + xy - sourceLocation;
                    foreach (var r in unit.Render())
                    {
                        r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location) + Traits.Util.CenterOfCell(targetCell),
                                        wr.GetPaletteIndex(r.Palette),
                                        r.Scale * r.Sprite.size);
                    }
                }

                // Unit tiles
                foreach (var unit in power.UnitsInRange(sourceLocation))
                {
                    var targetCell = unit.Location + xy - sourceLocation;
                    var canEnter   = unit.Trait <Chronoshiftable>().CanChronoshiftTo(unit, targetCell, false);
                    var tile       = canEnter ? validTile : invalidTile;
                    tile.DrawAt(wr, Game.CellSize * targetCell, "terrain");
                }
            }