Esempio n. 1
0
        public void GetFacingGizmo(ref Command_Action command)
        {
            command              = new Command_Action();
            command.icon         = GraphicCache.FlipIcon;
            command.defaultLabel = "switchfacing".TranslateSimple();
            command.defaultDesc  = "switchfacingdesc".TranslateSimple();
            command.action       = delegate
            {
                if (Parent.Rotation.IsHorizontal)
                {
                    if (facing == LinkDirections.Left)
                    {
                        facing = LinkDirections.Right;
                    }
                    else
                    {
                        facing = LinkDirections.Left;
                    }
                }
                else
                {
                    if (facing == LinkDirections.Up)
                    {
                        facing = LinkDirections.Down;
                    }
                    else
                    {
                        facing = LinkDirections.Up;
                    }
                }

                UpdateWindow();
            };
        }
Esempio n. 2
0
        public override void DrawWorker(Vector3 loc, Rot4 rot, ThingDef thingDef, Thing thing, float extraRotation)
        {
            int num = 0;

            if (thingDef.PlaceWorkers.All(p => p.AllowsPlacing(thingDef, loc.ToIntVec3(), rot, Find.CurrentMap).Accepted))
            {
                int num2 = 1;
                for (int i = 0; i < 4; i++)
                {
                    IntVec3 c = loc.ToIntVec3() + GenAdj.CardinalDirections[i];
                    if (this.IsWall(c, Find.CurrentMap))
                    {
                        num += num2;
                    }
                    num2 *= 2;
                }
            }
            LinkDirections linkSet  = (LinkDirections)num;
            var            material = this.subMats[(int)linkSet];

            material.shader = ShaderDatabase.Transparent;

            Mesh       mesh       = this.MeshAt(rot);
            Quaternion quaternion = this.QuatFromRot(rot);

            if (extraRotation != 0f)
            {
                quaternion *= Quaternion.Euler(Vector3.up * extraRotation);
            }
            Graphics.DrawMesh(mesh, loc, quaternion, material, 0);
            if (this.ShadowGraphic != null)
            {
                this.ShadowGraphic.DrawWorker(loc, rot, thingDef, thing, extraRotation);
            }
        }
Esempio n. 3
0
        public void DrawGhost(IntVec3 origin)
        {
            IntVec3 cell = origin + Position;

            if (_thingDef != null)
            {
                // normal thingdef graphic
                if (_thingDef.graphicData.linkFlags == LinkFlags.None)
                {
                    GhostDrawer.DrawGhostThing(cell, _rotation, _thingDef, null, Resources.ghostColor(CanPlace(origin)), AltitudeLayer.Blueprint);
                }

                // linked thingdef graphic
                else
                {
                    Material material;
                    Color    color = Resources.ghostColor(CanPlace(origin));
                    int      hash  = color.GetHashCode() * _rotation.GetHashCode();
                    if (!_cachedMaterials.TryGetValue(hash, out material))
                    {
                        // get a colored version (ripped from GhostDrawer.DrawGhostThing)
                        Graphic_Linked graphic = (Graphic_Linked)_thingDef.graphic.GetColoredVersion(ShaderDatabase.Transparent,
                                                                                                     color,
                                                                                                     Color.white);

                        // atlas contains all possible link graphics
                        Material atlas = graphic.MatSingle;

                        // loop over cardinal directions, and set the correct bits (e.g. 1, 2, 4, 8).
                        int linkInt = 0;
                        int dirInt  = 1;
                        for (int i = 0; i < 4; i++)
                        {
                            if (blueprint.ShouldLinkWith(Position + GenAdj.CardinalDirections[i], _thingDef))
                            {
                                linkInt += dirInt;
                            }
                            dirInt *= 2;
                        }

                        // translate int to bitmask (flags)
                        LinkDirections linkSet = (LinkDirections)linkInt;

                        // get and cache the final material
                        material = MaterialAtlasPool.SubMaterialFromAtlas(atlas, linkSet);
                        _cachedMaterials.Add(hash, material);
                    }

                    // draw the thing.
                    Vector3 position = (cell).ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays);
                    Graphics.DrawMesh(MeshPool.plane10, position, Quaternion.identity, material, 0);
                }
            }
            else
            {
                Vector3 position = (cell).ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays);
                Graphics.DrawMesh(MeshPool.plane10, position, Quaternion.identity, Resources.ghostFloorMaterial(CanPlace(origin)), 0);
            }
        }
 public static Material SubMaterialFromAtlas(Material mat, LinkDirections LinkSet)
 {
     if (!MaterialAtlasPool.atlasDict.ContainsKey(mat))
     {
         MaterialAtlasPool.atlasDict.Add(mat, new MaterialAtlasPool.MaterialAtlas(mat));
     }
     return(MaterialAtlasPool.atlasDict[mat].SubMat(LinkSet));
 }
 public Material SubMat(LinkDirections linkSet)
 {
     if ((int)linkSet >= this.subMats.Length)
     {
         Log.Warning("Cannot get submat of index " + (int)linkSet + ": out of range.");
         return(BaseContent.BadMat);
     }
     return(this.subMats[(uint)linkSet]);
 }
            public Material SubMat(LinkDirections linkSet)
            {
                Material result;

                if ((int)linkSet >= this.subMats.Length)
                {
                    Log.Warning("Cannot get submat of index " + (int)linkSet + ": out of range.", false);
                    result = BaseContent.BadMat;
                }
                else
                {
                    result = this.subMats[(int)linkSet];
                }
                return(result);
            }
Esempio n. 7
0
 private bool SetFacing(bool overhangFwd, bool overhangBwd)
 {
     if (overhangFwd != overhangBwd)
     {
         if (overhangFwd)
         {
             facing = horizontal ? LinkDirections.Left : LinkDirections.Down;
         }
         if (overhangBwd)
         {
             facing = horizontal ? LinkDirections.Right : LinkDirections.Up;
         }
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
        protected Material LinkedDrawMatFrom(Thing parent, IntVec3 cell)
        {
            int num  = 0;
            int num2 = 1;

            for (int i = 0; i < 4; i++)
            {
                if (this.ShouldLinkWith(new Rot4(i), parent))
                {
                    num += num2;
                }
                num2 *= 2;
            }
            LinkDirections linkSet = (LinkDirections)num;

            return(LinkedMaterial(parent, linkSet));
        }
Esempio n. 9
0
        protected Material LinkedDrawMatFrom(Thing parent, IntVec3 cell)
        {
            int num1 = 0;
            int num2 = 1;

            for (int index = 0; index < 4; ++index)
            {
                if (this.ShouldLinkWith(cell + GenAdj.CardinalDirections[index], parent))
                {
                    num1 += num2;
                }
                num2 *= 2;
            }
            LinkDirections LinkSet = (LinkDirections)num1;

            return(MaterialAtlasPool.SubMaterialFromAtlas(this.subGraphic.MatSingleFor(parent), LinkSet));
        }
Esempio n. 10
0
        public Material LinkedDrawMatFrom(Graphic_LinkedCornerFiller graphic, Thing parent, IntVec3 cell)
        {
            int num  = 0;
            int num2 = 1;

            for (int i = 0; i < 4; i++)
            {
                IntVec3 c = cell + GenAdj.CardinalDirections[i];
                if (graphic.ShouldLinkWith(c, parent))
                {
                    num += num2;
                }
                num2 *= 2;
            }
            LinkDirections linkSet = (LinkDirections)num;

            return(MaterialAtlasPool.SubMaterialFromAtlas(graphic.subGraphic.MatSingleFor(parent), linkSet));
        }
Esempio n. 11
0
        protected Material LinkedDrawMatFrom(Thing parent, IntVec3 cell)
        {
            int num  = 0;
            int num2 = 1;

            for (int i = 0; i < 4; i++)
            {
                IntVec3 c = cell + GenAdj.CardinalDirections[i];
                if (this.ShouldLinkWith(c, parent))
                {
                    num += num2;
                }
                num2 *= 2;
            }
            LinkDirections linkSet = (LinkDirections)num;

            return(LinkedMaterial(parent, linkSet));
        }
Esempio n. 12
0
        protected Material LinkedDrawMatFrom(Thing parent, IntVec3 cell)
        {
            int num  = 0;
            int num2 = 1;

            for (int i = 0; i < 4; i++)
            {
                IntVec3 c = cell + GenAdj.CardinalDirections[i];
                if (this.ShouldLinkWith(c, parent))
                {
                    num += num2;
                }
                num2 *= 2;
            }
            LinkDirections linkSet = (LinkDirections)num;
            Material       mat     = this.subGraphic.MatSingleFor(parent);

            return(MaterialAtlasPool.SubMaterialFromAtlas(mat, linkSet));
        }
Esempio n. 13
0
        public static IntVec3 FindEnd(IntVec3 center, Rot4 rot, IntVec2 size, bool again)
        {
            LinkDirections dirA;
            LinkDirections dirB;
            IntVec3        adjust;
            int            delta = again ? +1 : -1;

            if (rot.IsHorizontal)
            {
                dirA   = LinkDirections.Up;
                dirB   = LinkDirections.Down;
                adjust = new IntVec3(1, 0, delta);
            }
            else
            {
                dirA   = LinkDirections.Right;
                dirB   = LinkDirections.Left;
                adjust = new IntVec3(delta, 0, 1);
            }
            LinkDirections dir = again ? dirB : dirA;

            return(GenAdj.CellsAdjacentAlongEdge(center + adjust, rot, size, dir).FirstOrFallback());
        }
Esempio n. 14
0
        public static bool IsInterior(this IntVec3 cell, IntVec3 origin, LinkDirections facing)
        {
            switch (facing)
            {
            case LinkDirections.Up:
                if (cell.z < origin.z)
                {
                    return(true);
                }
                break;

            case LinkDirections.Right:
                if (cell.x < origin.x)
                {
                    return(true);
                }
                break;

            case LinkDirections.Down:
                if (cell.z > origin.z)
                {
                    return(true);
                }
                break;

            case LinkDirections.Left:
                if (cell.x > origin.x)
                {
                    return(true);
                }
                break;

            case LinkDirections.None:
                return(false);
            }
            return(false);
        }
Esempio n. 15
0
        public void CheckFacing()
        {
            bool           before   = isFacingSet;
            LinkDirections fwdDir   = Rotation.IsHorizontal ? LinkDirections.Right : LinkDirections.Up;
            LinkDirections bwdDir   = Rotation.IsHorizontal ? LinkDirections.Left : LinkDirections.Down;
            int            fwdVotes = 0;
            int            bwdVotes = 0;

            foreach (var line in scanLines.Where(x => x.facingSet))
            {
                if (line.facing == fwdDir)
                {
                    fwdVotes++;
                }
                if (line.facing == bwdDir)
                {
                    bwdVotes++;
                }
            }
            if (fwdVotes != bwdVotes)
            {
                Facing      = fwdVotes > bwdVotes ? fwdDir : bwdDir;
                isFacingSet = true;
            }
            else
            {
                isFacingSet = false;
                foreach (var line in scanLines)
                {
                    line.Reset();
                }
            }
            if (!needsUpdate && isFacingSet != before)
            {
                needsUpdate = true;
            }
        }
Esempio n. 16
0
        // in short, get all the cells in the 'radius' of the window, whichever 'side' of the window has less roof cells becomes the side that is being faced, i.e. light goes to the side with more roofs
        public List <IntVec3> TryResolveFacing()
        {
            var cells = WindowUtility.GetWindowCells(Parent, true);

            int count     = 0;
            int leftCount = 0;
            var map       = Parent.Map;

            foreach (var c in cells)
            {
                if (Parent.Rotation.IsHorizontal)
                {
                    if (c.x > Parent.Position.x)
                    {
                        if (c.Roofed(map))
                        {
                            leftCount++;
                        }
                        else
                        if (c.Roofed(map))
                        {
                            count++;
                        }
                    }
                }
                else
                {
                    if (c.z > Parent.Position.z)
                    {
                        if (c.Roofed(map))
                        {
                            leftCount++;
                        }
                        else
                        if (c.Roofed(map))
                        {
                            count++;
                        }
                    }
                }
            }

            if (count > leftCount)
            {
                if (Parent.Rotation.IsHorizontal)
                {
                    facing = LinkDirections.Left;
                }
                else
                {
                    facing = LinkDirections.Down;
                }
            }
            else if (count < leftCount)
            {
                if (Parent.Rotation.IsHorizontal)
                {
                    facing = LinkDirections.Right;
                }
                else
                {
                    facing = LinkDirections.Up;
                }
            }
            else
            {
                facing = LinkDirections.None;
            }

            return(cells);
        }
Esempio n. 17
0
        public static IEnumerable <IntVec3> CellsAdjacentAlongEdge(IntVec3 thingCent, Rot4 thingRot, IntVec2 thingSize, LinkDirections dir)
        {
            GenAdj.AdjustForRotation(ref thingCent, ref thingSize, thingRot);
            int minX = thingCent.x - (thingSize.x - 1) / 2 - 1;
            int minZ = thingCent.z - (thingSize.z - 1) / 2 - 1;
            int maxX = minX + thingSize.x + 1;
            int maxZ = minZ + thingSize.z + 1;

            if (dir == LinkDirections.Down)
            {
                for (int x = minX; x <= maxX; x++)
                {
                    yield return(new IntVec3(x, thingCent.y, minZ - 1));
                }
            }
            if (dir == LinkDirections.Up)
            {
                for (int x2 = minX; x2 <= maxX; x2++)
                {
                    yield return(new IntVec3(x2, thingCent.y, maxZ + 1));
                }
            }
            if (dir == LinkDirections.Left)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    yield return(new IntVec3(minX - 1, thingCent.y, z));
                }
            }
            if (dir == LinkDirections.Right)
            {
                for (int z2 = minZ; z2 <= maxZ; z2++)
                {
                    yield return(new IntVec3(maxX + 1, thingCent.y, z2));
                }
            }
        }
Esempio n. 18
0
 public virtual Material LinkedMaterial(Thing parent, LinkDirections linkSet)
 {
     return(this.subMats[(int)linkSet]);
 }
Esempio n. 19
0
        public static IEnumerable <IntVec3> CellsAdjacentAlongEdge(IntVec3 thingCent, Rot4 thingRot, IntVec2 thingSize, LinkDirections dir)
        {
            AdjustForRotation(ref thingCent, ref thingSize, thingRot);
            int minX = thingCent.x - (thingSize.x - 1) / 2 - 1;
            int minZ = thingCent.z - (thingSize.z - 1) / 2 - 1;
            int maxX = minX + thingSize.x + 1;
            int maxZ = minZ + thingSize.z + 1;

            if (dir == LinkDirections.Down)
            {
                int x2 = minX;
                if (x2 <= maxX)
                {
                    yield return(new IntVec3(x2, thingCent.y, minZ - 1));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            if (dir == LinkDirections.Up)
            {
                int x = minX;
                if (x <= maxX)
                {
                    yield return(new IntVec3(x, thingCent.y, maxZ + 1));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            if (dir == LinkDirections.Left)
            {
                int z2 = minZ;
                if (z2 <= maxZ)
                {
                    yield return(new IntVec3(minX - 1, thingCent.y, z2));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            if (dir == LinkDirections.Right)
            {
                int z = minZ;
                if (z <= maxZ)
                {
                    yield return(new IntVec3(maxX + 1, thingCent.y, z));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
        }