Exemplo n.º 1
0
        /// <summary>
        /// Get edge of map the pawn is closest too
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        public static Rot4 ClosestEdge(Pawn pawn, Map map)
        {
            IntVec2 mapSize  = new IntVec2(map.Size.x, map.Size.z);
            IntVec2 position = new IntVec2(pawn.Position.x, pawn.Position.z);

            SPTuple2 <Rot4, int> hDistance = Math.Abs(position.x) < Math.Abs(position.x - mapSize.x) ? new SPTuple2 <Rot4, int>(Rot4.West, position.x) : new SPTuple2 <Rot4, int>(Rot4.East, Math.Abs(position.x - mapSize.x));
            SPTuple2 <Rot4, int> vDistance = Math.Abs(position.z) < Math.Abs(position.z - mapSize.z) ? new SPTuple2 <Rot4, int>(Rot4.South, position.z) : new SPTuple2 <Rot4, int>(Rot4.North, Math.Abs(position.z - mapSize.z));

            return(hDistance.Second <= vDistance.Second ? hDistance.First : vDistance.First);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draw selection brackets for pawn with angle
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="bracketLocs"></param>
        /// <param name="obj"></param>
        /// <param name="worldPos"></param>
        /// <param name="worldSize"></param>
        /// <param name="dict"></param>
        /// <param name="textureSize"></param>
        /// <param name="pawnAngle"></param>
        /// <param name="jumpDistanceFactor"></param>
        public static void CalculateSelectionBracketPositionsWorldForMultiCellPawns <T>(Vector3[] bracketLocs, T obj, Vector3 worldPos, Vector2 worldSize, Dictionary <T, float> dict, Vector2 textureSize, float pawnAngle = 0f, float jumpDistanceFactor = 1f)
        {
            float num;
            float num2;

            if (!dict.TryGetValue(obj, out num))
            {
                num2 = 1f;
            }
            else
            {
                num2 = Mathf.Max(0f, 1f - (Time.realtimeSinceStartup - num) / 0.07f);
            }
            float num3 = num2 * 0.2f * jumpDistanceFactor;
            float num4 = 0.5f * (worldSize.x - textureSize.x) + num3;
            float num5 = 0.5f * (worldSize.y - textureSize.y) + num3;
            float y    = AltitudeLayer.MetaOverlays.AltitudeFor();

            bracketLocs[0] = new Vector3(worldPos.x - num4, y, worldPos.z - num5);
            bracketLocs[1] = new Vector3(worldPos.x + num4, y, worldPos.z - num5);
            bracketLocs[2] = new Vector3(worldPos.x + num4, y, worldPos.z + num5);
            bracketLocs[3] = new Vector3(worldPos.x - num4, y, worldPos.z + num5);

            switch (pawnAngle)
            {
            case 45f:
                for (int i = 0; i < 4; i++)
                {
                    float xPos = bracketLocs[i].x - worldPos.x;
                    float yPos = bracketLocs[i].z - worldPos.z;
                    SPTuple2 <float, float> newPos = SPTrig.RotatePointClockwise(xPos, yPos, 45f);
                    bracketLocs[i].x = newPos.First + worldPos.x;
                    bracketLocs[i].z = newPos.Second + worldPos.z;
                }
                break;

            case -45:
                for (int i = 0; i < 4; i++)
                {
                    float xPos = bracketLocs[i].x - worldPos.x;
                    float yPos = bracketLocs[i].z - worldPos.z;
                    SPTuple2 <float, float> newPos = SPTrig.RotatePointCounterClockwise(xPos, yPos, 45f);
                    bracketLocs[i].x = newPos.First + worldPos.x;
                    bracketLocs[i].z = newPos.Second + worldPos.z;
                }
                break;
            }
        }
Exemplo n.º 3
0
 public bool Equals(SPTuple2 <T1, T2> other)
 {
     return(EqualityComparer <T1> .Default.Equals(this.first, other.first) && EqualityComparer <T2> .Default.Equals(this.second, other.second));
 }