当前位置: 首页>>代码示例>>C#>>正文


C# World.IsCellBuildable方法代码示例

本文整理汇总了C#中World.IsCellBuildable方法的典型用法代码示例。如果您正苦于以下问题:C# World.IsCellBuildable方法的具体用法?C# World.IsCellBuildable怎么用?C# World.IsCellBuildable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在World的用法示例。


在下文中一共展示了World.IsCellBuildable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetLineBuildCells

        public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
        {
            var lbi = world.Map.Rules.Actors[name].Traits.Get<LineBuildInfo>();
            var topLeft = location;	// 1x1 assumption!

            if (world.IsCellBuildable(topLeft, bi))
                yield return topLeft;

            // Start at place location, search outwards
            // TODO: First make it work, then make it nice
            var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) };
            int[] dirs = { 0, 0, 0, 0 };
            for (int d = 0; d < 4; d++)
            {
                for (int i = 1; i < lbi.Range; i++)
                {
                    if (dirs[d] != 0)
                        continue;

                    var cell = topLeft + i * vecs[d];
                    if (world.IsCellBuildable(cell, bi))
                        continue; // Cell is empty; continue search

                    // Cell contains an actor. Is it the type we want?
                    if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
                    (
                        a.Actor.Location == cell &&
                        a.Actor.Info.Traits.Get<LineBuildNodeInfo>().Types.Intersect(lbi.NodeTypes).Any()
                    )))
                        dirs[d] = i; // Cell contains actor of correct type
                    else
                        dirs[d] = -1; // Cell is blocked by another actor type
                }

                // Place intermediate-line sections
                if (dirs[d] > 0)
                    for (int i = 1; i < dirs[d]; i++)
                        yield return topLeft + i * vecs[d];
            }
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:40,代码来源:Util.cs

示例2: GetLineBuildCells

        public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
        {
            var lbi = world.Map.Rules.Actors[name].TraitInfo<LineBuildInfo>();
            var topLeft = location;	// 1x1 assumption!

            if (world.IsCellBuildable(topLeft, bi))
                yield return topLeft;

            // Start at place location, search outwards
            // TODO: First make it work, then make it nice
            var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) };
            int[] dirs = { 0, 0, 0, 0 };
            for (var d = 0; d < 4; d++)
            {
                for (var i = 1; i < lbi.Range; i++)
                {
                    if (dirs[d] != 0)
                        continue;

                    var cell = topLeft + i * vecs[d];
                    if (world.IsCellBuildable(cell, bi))
                        continue; // Cell is empty; continue search

                    // Cell contains an actor. Is it the type we want?
                    var hasConnector = world.ActorMap.GetActorsAt(cell)
                        .Any(a => a.Info.TraitInfos<LineBuildNodeInfo>()
                            .Any(info => info.Types.Overlaps(lbi.NodeTypes) && info.Connections.Contains(vecs[d])));

                    dirs[d] = hasConnector ? i : -1;
                }

                // Place intermediate-line sections
                if (dirs[d] > 0)
                    for (var i = 1; i < dirs[d]; i++)
                        yield return topLeft + i * vecs[d];
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:37,代码来源:BuildingUtils.cs

示例3: DrawBuildingGrid

        public void DrawBuildingGrid( WorldRenderer wr, World world, string name )
        {
            var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
            var topLeft = position - FootprintUtils.AdjustForBuildingSize( this );

            var cells = new Dictionary<int2, bool>();
            // Linebuild for walls.
            // Assumes a 1x1 footprint; weird things will happen for other footprints
            if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
            {
                foreach( var t in BuildingUtils.GetLineBuildCells( world, topLeft, name, this ) )
                    cells.Add( t, IsCloseEnoughToBase( world, world.LocalPlayer, name, t ) );
            }
            else
            {
                var res = world.WorldActor.Trait<ResourceLayer>();
                var isCloseEnough = IsCloseEnoughToBase(world, world.LocalPlayer, name, topLeft);
                foreach (var t in FootprintUtils.Tiles(name, this, topLeft))
                    cells.Add( t, isCloseEnough && world.IsCellBuildable(t, WaterBound) && res.GetResource(t) == null );
            }
            wr.uiOverlay.DrawGrid( wr, cells );
        }
开发者ID:geckosoft,项目名称:OpenRA,代码行数:22,代码来源:Building.cs

示例4: RenderAfterWorld

        public void RenderAfterWorld(WorldRenderer wr, World world)
        {
            var position = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
            var topLeft = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo);

            var actorInfo = Rules.Info[Building];
            foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
                dec.Render(wr, world, actorInfo, position.CenterPosition);	/* 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
            {
                if (!initialized)
                {
                    var rbi = Rules.Info[Building].Traits.Get<RenderBuildingInfo>();
                    var palette = rbi.Palette ?? (Producer.Owner != null ?
                                                  rbi.PlayerPalette + Producer.Owner.InternalName : null);

                    preview = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette));
                    initialized = true;
                }

                var offset = topLeft.CenterPosition + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero;
                foreach (var r in preview)
                    r.OffsetBy(offset).Render(wr);

                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);
            }

            var pal = wr.Palette("terrain");
            foreach (var c in cells)
            {
                var tile = c.Value ? buildOk : buildBlocked;
                new SpriteRenderable(tile, c.Key.CenterPosition,
                    WVec.Zero, -511, pal, 1f, true).Render(wr);
            }
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:47,代码来源:PlaceBuildingOrderGenerator.cs

示例5: RenderAboveShroud

        public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
        {
            var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
            var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo);
            var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, buildingInfo);
            var rules = world.Map.Rules;

            var actorInfo = rules.Actors[building];
            foreach (var dec in actorInfo.TraitInfos<IPlaceBuildingDecorationInfo>())
                foreach (var r in dec.Render(wr, world, actorInfo, offset))
                    yield return r;

            var cells = new Dictionary<CPos, bool>();

            var plugInfo = rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
            if (plugInfo != null)
            {
                if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1)
                    throw new InvalidOperationException("Plug requires a 1x1 sized Building");

                cells.Add(topLeft, AcceptsPlug(topLeft, plugInfo));
            }
            else if (rules.Actors[building].HasTraitInfo<LineBuildInfo>())
            {
                // Linebuild for walls.
                if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1)
                    throw new InvalidOperationException("LineBuild requires a 1x1 sized Building");

                if (!Game.GetModifierKeys().HasModifier(Modifiers.Shift))
                    foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, building, buildingInfo))
                        cells.Add(t, buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, t));
                else
                    cells.Add(topLeft, buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, topLeft));
            }
            else
            {
                if (!initialized)
                {
                    var td = new TypeDictionary()
                    {
                        new FactionInit(faction),
                        new OwnerInit(queue.Actor.Owner),
                        new HideBibPreviewInit()
                    };

                    var init = new ActorPreviewInitializer(rules.Actors[building], wr, td);
                    preview = rules.Actors[building].TraitInfos<IRenderActorPreviewInfo>()
                        .SelectMany(rpi => rpi.RenderPreview(init))
                        .ToArray();

                    initialized = true;
                }

                var previewRenderables = preview
                    .SelectMany(p => p.Render(wr, offset))
                    .OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey);

                foreach (var r in previewRenderables)
                    yield return r;

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

            var pal = wr.Palette(placeBuildingInfo.Palette);
            var topLeftPos = world.Map.CenterOfCell(topLeft);
            foreach (var c in cells)
            {
                var tile = c.Value ? buildOk : buildBlocked;
                var pos = world.Map.CenterOfCell(c.Key);
                yield return new SpriteRenderable(tile, pos, new WVec(0, 0, topLeftPos.Z - pos.Z),
                    -511, pal, 1f, true);
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:76,代码来源:PlaceBuildingOrderGenerator.cs

示例6: RenderBeforeWorld

        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" );
        }
开发者ID:Iran,项目名称:ClassicRA,代码行数:33,代码来源:PlaceBuildingOrderGenerator.cs

示例7: RenderAfterWorld

        public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
        {
            var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
            var topLeft = xy - FootprintUtils.AdjustForBuildingSize(BuildingInfo);

            var rules = world.Map.Rules;

            var actorInfo = rules.Actors[Building];
            foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
                foreach (var r in dec.Render(wr, world, actorInfo, world.Map.CenterOfCell(xy)))
                    yield return r;

            var cells = new Dictionary<CPos, bool>();
            // Linebuild for walls.
            // Requires a 1x1 footprint
            if (rules.Actors[Building].Traits.Contains<LineBuildInfo>())
            {
                if (BuildingInfo.Dimensions.X != 1 || BuildingInfo.Dimensions.Y != 1)
                    throw new InvalidOperationException("LineBuild requires a 1x1 sized Building");

                foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, Building, BuildingInfo))
                    cells.Add(t, BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, t));
            }
            else
            {
                if (!initialized)
                {
                    var init = new ActorPreviewInitializer(rules.Actors[Building], Producer.Owner, wr, new TypeDictionary());
                    preview = rules.Actors[Building].Traits.WithInterface<IRenderActorPreviewInfo>()
                        .SelectMany(rpi => rpi.RenderPreview(init))
                        .ToArray();

                    initialized = true;
                }

                var comparer = new RenderableComparer(wr);
                var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo);
                var previewRenderables = preview
                    .SelectMany(p => p.Render(wr, offset))
                    .OrderBy(r => r, comparer);

                foreach (var r in previewRenderables)
                    yield return r;

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

            var pal = wr.Palette("terrain");
            foreach (var c in cells)
            {
                var tile = c.Value ? buildOk : buildBlocked;
                yield return new SpriteRenderable(tile, world.Map.CenterOfCell(c.Key),
                    WVec.Zero, -511, pal, 1f, true);
            }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:58,代码来源:PlaceBuildingOrderGenerator.cs

示例8: DrawBuildingGrid

        public void DrawBuildingGrid( World world, string name, BuildingInfo bi )
        {
            var position = Game.controller.MousePosition.ToInt2();
            var topLeft = position - Footprint.AdjustForBuildingSize( bi );

            // Linebuild for walls.
            // Assumes a 1x1 footprint; weird things will happen for other footprints
            if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
            {
                foreach (var t in LineBuildUtils.GetLineBuildCells(world, topLeft, name, bi))
                    spriteRenderer.DrawSprite(world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, t)
                        ? buildOk : buildBlocked, Game.CellSize * t, "terrain");
            }
            else
            {
                var res = world.WorldActor.traits.Get<ResourceLayer>();
                var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
                foreach (var t in Footprint.Tiles(name, bi, topLeft))
                    spriteRenderer.DrawSprite((isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null)
                        ? buildOk : buildBlocked, Game.CellSize * t, "terrain");
            }

            spriteRenderer.Flush();
        }
开发者ID:comradpara,项目名称:OpenRA,代码行数:24,代码来源:UiOverlay.cs

示例9: RenderBeforeWorld

        public void RenderBeforeWorld( WorldRenderer wr, World world )
        {
            var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
            var topLeft = position - FootprintUtils.AdjustForBuildingSize( BuildingInfo );

            var cells = new Dictionary<int2, 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(Game.CellSize*topLeft + r.Pos,
                                    wr.GetPaletteIndex(r.Palette ?? world.LocalPlayer.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.WaterBound) && res.GetResource(t) == null );
            }

            wr.uiOverlay.DrawGrid( wr, cells );
        }
开发者ID:patthoyts,项目名称:OpenRA,代码行数:28,代码来源:PlaceBuildingOrderGenerator.cs


注:本文中的World.IsCellBuildable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。