예제 #1
0
        private void RenderCancelHighlights()
        {
            selectedThings.Clear();
            CellRect dragRect = CellRect.FromLimits(DragStart, UI.MouseCell());

            foreach (IntVec3 CurCell in dragRect)
            {
                if (!CurCell.InBounds(Find.CurrentMap))
                {
                    continue;
                }
                var thingslist = CurCell.GetThingList(Find.CurrentMap);
                for (int i = 0; i < thingslist.Count; i++)
                {
                    var t = thingslist[i];
                    if (CanCancelBlueprint(t) && !selectedThings.Contains(t))
                    {
                        selectedThings.Add(t);
                        Vector3 drawPos = t.DrawPos;
                        drawPos.y = AltitudeLayer.MetaOverlays.AltitudeFor();
                        Graphics.DrawMesh(MeshPool.plane10, drawPos, Quaternion.identity, DesignatorUtility.DragHighlightThingMat, 0);
                    }
                }
            }
        }
        private void MergeRandomChildren()
        {
            if (this.children.Count < 4)
            {
                return;
            }
            int num = GenMath.RoundRandom((float)this.children.Count / 6f);

            for (int i = 0; i < num; i++)
            {
                SymbolResolver_BasePart_Outdoors_Division_Grid.Child child = this.children.Find((SymbolResolver_BasePart_Outdoors_Division_Grid.Child x) => !x.merged);
                if (child == null)
                {
                    break;
                }
                SymbolResolver_BasePart_Outdoors_Division_Grid.Child child3 = this.children.Find((SymbolResolver_BasePart_Outdoors_Division_Grid.Child x) => x != child && ((Mathf.Abs(x.gridX - child.gridX) == 1 && x.gridY == child.gridY) || (Mathf.Abs(x.gridY - child.gridY) == 1 && x.gridX == child.gridX)));
                if (child3 != null)
                {
                    this.children.Remove(child);
                    this.children.Remove(child3);
                    SymbolResolver_BasePart_Outdoors_Division_Grid.Child child2 = new SymbolResolver_BasePart_Outdoors_Division_Grid.Child();
                    child2.gridX  = Mathf.Min(child.gridX, child3.gridX);
                    child2.gridY  = Mathf.Min(child.gridY, child3.gridY);
                    child2.merged = true;
                    child2.rect   = CellRect.FromLimits(Mathf.Min(child.rect.minX, child3.rect.minX), Mathf.Min(child.rect.minZ, child3.rect.minZ), Mathf.Max(child.rect.maxX, child3.rect.maxX), Mathf.Max(child.rect.maxZ, child3.rect.maxZ));
                    this.children.Add(child2);
                }
            }
        }
예제 #3
0
 private void MergeRandomChildren()
 {
     if (this.children.Count >= 4)
     {
         int num  = GenMath.RoundRandom((float)((float)this.children.Count / 6.0));
         int num2 = 0;
         while (num2 < num)
         {
             Child child = this.children.Find((Child x) => !x.merged);
             if (child != null)
             {
                 Child child2 = this.children.Find((Child x) => x != child && ((Mathf.Abs(x.gridX - child.gridX) == 1 && x.gridY == child.gridY) || (Mathf.Abs(x.gridY - child.gridY) == 1 && x.gridX == child.gridX)));
                 if (child2 != null)
                 {
                     this.children.Remove(child);
                     this.children.Remove(child2);
                     Child child3 = new Child();
                     child3.gridX  = Mathf.Min(child.gridX, child2.gridX);
                     child3.gridY  = Mathf.Min(child.gridY, child2.gridY);
                     child3.merged = true;
                     child3.rect   = CellRect.FromLimits(Mathf.Min(child.rect.minX, child2.rect.minX), Mathf.Min(child.rect.minZ, child2.rect.minZ), Mathf.Max(child.rect.maxX, child2.rect.maxX), Mathf.Max(child.rect.maxZ, child2.rect.maxZ));
                     this.children.Add(child3);
                 }
                 num2++;
                 continue;
             }
             break;
         }
     }
 }
예제 #4
0
 private void MergeRandomChildren()
 {
     if (children.Count >= 4)
     {
         int num = GenMath.RoundRandom((float)children.Count / 6f);
         for (int i = 0; i < num; i++)
         {
             Child child = children.Find((Child x) => !x.merged);
             if (child == null)
             {
                 break;
             }
             Child child2 = children.Find((Child x) => x != child && ((Mathf.Abs(x.gridX - child.gridX) == 1 && x.gridY == child.gridY) || (Mathf.Abs(x.gridY - child.gridY) == 1 && x.gridX == child.gridX)));
             if (child2 != null)
             {
                 children.Remove(child);
                 children.Remove(child2);
                 Child child3 = new Child();
                 child3.gridX  = Mathf.Min(child.gridX, child2.gridX);
                 child3.gridY  = Mathf.Min(child.gridY, child2.gridY);
                 child3.merged = true;
                 child3.rect   = CellRect.FromLimits(Mathf.Min(child.rect.minX, child2.rect.minX), Mathf.Min(child.rect.minZ, child2.rect.minZ), Mathf.Max(child.rect.maxX, child2.rect.maxX), Mathf.Max(child.rect.maxZ, child2.rect.maxZ));
                 children.Add(child3);
             }
         }
     }
 }
예제 #5
0
 private static Exception Finalizer(Exception __exception, Pawn pawn)
 {
     if (__exception != null)
     {
         Log.Error("Z-Levels caught an exception: " + __exception + ", trying to fix it");
         ZUtils.TryFixPawnError(pawn);
         IntVec3 nextCell = pawn.pather.nextCell;
         foreach (IntVec3 item in CellRect.FromLimits(nextCell, pawn.Position).ExpandedBy(1))
         {
             if (item.InBounds(pawn.Map))
             {
                 List <Thing> thingList = item.GetThingList(pawn.Map);
                 for (int i = 0; i < thingList.Count; i++)
                 {
                     Pawn pawn2 = thingList[i] as Pawn;
                     if (pawn2 != null && pawn2 != pawn && pawn2.GetPosture() == PawnPosture.Standing)
                     {
                         ZUtils.TryFixPawnError(pawn);
                     }
                 }
             }
         }
         return(__exception);
     }
     return(null);
 }
예제 #6
0
        public static CellRect ExpandToContain(this CellRect rect, Vector3 point)
        {
            int maxX = (int)Mathf.Max(rect.maxX, point.x - 1);
            int minX = (int)Mathf.Min(rect.minX, point.x);
            int maxZ = (int)Mathf.Max(rect.maxZ, point.z - 1);
            int minZ = (int)Mathf.Min(rect.minZ, point.z);

            return(CellRect.FromLimits(minX, minZ, maxX, maxZ));
        }
예제 #7
0
        static void Postfix(ref CellRect __result)
        {
            var center  = __result.CenterVector3;
            var corners = __result.Corners.Select(c => (c.ToVector3Shifted() - center).RotatedBy(-Find.CurrentMap.CarouselComp().current) + center);
            var min     = corners.Aggregate((a, b) => Vector3.Min(a, b));
            var max     = corners.Aggregate((a, b) => Vector3.Max(a, b));

            __result = CellRect.FromLimits(FloorVec(min), CeilVec(max));
        }
예제 #8
0
        public void EstablishConnections()
        {
            if (!parent.Spawned)
            {
                return;
            }
            List <CompShipLandingBeacon> list  = new List <CompShipLandingBeacon>();
            List <CompShipLandingBeacon> list2 = new List <CompShipLandingBeacon>();
            List <Thing> list3 = parent.Map.listerThings.ThingsOfDef(ThingDefOf.ShipLandingBeacon);

            foreach (Thing item in list3)
            {
                CompShipLandingBeacon compShipLandingBeacon = item.TryGetComp <CompShipLandingBeacon>();
                if (compShipLandingBeacon != null && CanLinkTo(compShipLandingBeacon))
                {
                    if (parent.Position.x == compShipLandingBeacon.parent.Position.x)
                    {
                        list2.Add(compShipLandingBeacon);
                    }
                    else if (parent.Position.z == compShipLandingBeacon.parent.Position.z)
                    {
                        list.Add(compShipLandingBeacon);
                    }
                }
            }
            foreach (CompShipLandingBeacon h in list)
            {
                foreach (CompShipLandingBeacon v in list2)
                {
                    Thing thing = list3.FirstOrDefault((Thing x) => x.Position.x == h.parent.Position.x && x.Position.z == v.parent.Position.z);
                    if (thing != null)
                    {
                        ShipLandingArea shipLandingArea = new ShipLandingArea(CellRect.FromLimits(thing.Position, parent.Position).ContractedBy(1), parent.Map);
                        shipLandingArea.beacons = new List <CompShipLandingBeacon>
                        {
                            this,
                            thing.TryGetComp <CompShipLandingBeacon>(),
                            v,
                            h
                        };
                        TryAddArea(shipLandingArea);
                    }
                }
            }
            for (int num = landingAreas.Count - 1; num >= 0; num--)
            {
                foreach (CompShipLandingBeacon beacon in landingAreas[num].beacons)
                {
                    if (!beacon.TryAddArea(landingAreas[num]))
                    {
                        RemoveArea(landingAreas[num]);
                        break;
                    }
                }
            }
        }
예제 #9
0
        protected override void ScatterAt(IntVec3 c, Map map, GenStepParams parms, int stackCount = 1)
        {
            base.ScatterAt(c, map, parms, stackCount);
            int      minX = recentLumpCells.Min((IntVec3 x) => x.x);
            int      minZ = recentLumpCells.Min((IntVec3 x) => x.z);
            int      maxX = recentLumpCells.Max((IntVec3 x) => x.x);
            int      maxZ = recentLumpCells.Max((IntVec3 x) => x.z);
            CellRect var  = CellRect.FromLimits(minX, minZ, maxX, maxZ);

            MapGenerator.SetVar("RectOfInterest", var);
        }
예제 #10
0
        protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count)
        {
            var s = new Stencil(map);

            s = s.BoundTo(CellRect.FromLimits(pos, s.bounds.RandomCell));
            var stuff = GenCity.RandomWallStuff(map);

            for (var dir = 0; dir < 4; dir++)
            {
                var sDir = s.Rotate(dir);
                sDir.Fill(sDir.MinX, sDir.MaxZ, sDir.MaxX, sDir.MaxZ, ThingDefOf.Wall, stuff, IsValidTile);
            }
        }
예제 #11
0
 public static bool CloserThingBetween(ThingDef thingDef, IntVec3 a, IntVec3 b, Map map, Thing thingToIgnore = null)
 {
     foreach (IntVec3 item in CellRect.FromLimits(a, b))
     {
         if (!(item == a) && !(item == b) && item.InBounds(map))
         {
             foreach (Thing thing in item.GetThingList(map))
             {
                 if ((thingToIgnore == null || thingToIgnore != thing) && (thing.def == thingDef || thing.def.entityDefToBuild == thingDef))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
        private void MergeRandomChildren()
        {
            if (children.Count < 4)
            {
                return;
            }

            var num = GenMath.RoundRandom(children.Count / 6f);

            for (var i = 0; i < num; i++)
            {
                var child =
                    children.Find(x => !x.merged);
                if (child == null)
                {
                    break;
                }

                var child3 =
                    children.Find(x =>
                                  x != child &&
                                  (Mathf.Abs(x.gridX - child.gridX) == 1 && x.gridY == child.gridY ||
                                   Mathf.Abs(x.gridY - child.gridY) == 1 && x.gridX == child.gridX));
                if (child3 == null)
                {
                    continue;
                }

                children.Remove(child);
                children.Remove(child3);
                var child2 =
                    new Child
                {
                    gridX  = Mathf.Min(child.gridX, child3.gridX),
                    gridY  = Mathf.Min(child.gridY, child3.gridY),
                    merged = true,
                    rect   = CellRect.FromLimits(Mathf.Min(child.rect.minX, child3.rect.minX),
                                                 Mathf.Min(child.rect.minZ, child3.rect.minZ),
                                                 Mathf.Max(child.rect.maxX, child3.rect.maxX),
                                                 Mathf.Max(child.rect.maxZ, child3.rect.maxZ))
                };
                children.Add(child2);
            }
        }
예제 #13
0
        public static IntVec3 GetSecondSwimSpotNear(IntVec3 root, IntVec3 swimSpot, Pawn swimmer, Map map)
        {
            int x = (root.x + swimSpot.x) / 2;
            int z = (root.z + swimSpot.z) / 2;

            if (root.x - swimSpot.x < 3 && root.x - swimSpot.x > 3)
            {
                x = swimSpot.x;
            }
            if (root.z - swimSpot.z < 3 && root.z - swimSpot.z > -3)
            {
                z = swimSpot.z;
            }
            CellRect cellRect = CellRect.FromLimits(x, z, root.x, root.z);

            cellRect.ClipInsideMap(map);
            foreach (IntVec3 cell in cellRect)
            {
                if (!cell.IsForbidden(swimmer) && cell.GetTerrain(map).HasModExtension <SwimmableWater>())
                {
                    bool swimmable = true;
                    foreach (IntVec3 cell2 in GenAdjFast.AdjacentCells8Way(cell))
                    {
                        if (!cell2.GetTerrain(map).HasModExtension <SwimmableWater>())
                        {
                            swimmable = false;
                            break;
                        }
                    }
                    if (swimmable)
                    {
                        //Log.Message(swimmer.Name + " found second swim spot at " + cell.x.ToString() + ", " + cell.z.ToString());
                        return(cell);
                    }
                }
            }
            if (swimSpot.GetTerrain(map).IsRiver)
            {
                return(swimSpot);
            }
            return(root);
        }
예제 #14
0
        static void Postfix(ref CellRect __result)
        {
            if (Find.CurrentMap == null)
            {
                return;
            }

            if (Time.frameCount != lastViewRectGetFrame)
            {
                var center  = __result.CenterVector3;
                var corners = __result.Corners.Select(c => (c.ToVector3Shifted() - center).RotatedBy(-Find.CurrentMap.CarouselComp().current) + center);
                var min     = corners.Aggregate((a, b) => Vector3.Min(a, b));
                var max     = corners.Aggregate((a, b) => Vector3.Max(a, b));

                lastViewRectGetFrame = Time.frameCount;
                lastViewRect         = CellRect.FromLimits(FloorVec(min), CeilVec(max));
            }

            __result = lastViewRect;
        }
예제 #15
0
        private void DebugVehicleTracksDrawer(IntVec3 c1, IntVec3 c2)
        {
            foreach (VehicleTrack track in Props.tracks)
            {
                foreach (IntVec3 cell in CellRect.FromLimits(c1, c2).Cells)
                {
                    GenDraw.DrawFieldEdges(new List <IntVec3>()
                    {
                        cell
                    }, Color.red);
                }
            }

            foreach (IntVec3 cell in WarningRect().Cells)
            {
                GenDraw.DrawFieldEdges(new List <IntVec3>()
                {
                    cell
                }, Color.red);
            }
        }
예제 #16
0
        public static IntVec3 GetRandomShorelineNear(IntVec3 root, IntVec3 swimSpot, Pawn swimmer, Map map)
        {
            CellRect cellRect = CellRect.FromLimits((root.x + swimSpot.x) / 2, (root.z + swimSpot.z) / 2, swimSpot.x, swimSpot.z);

            cellRect.ClipInsideMap(map);
            foreach (IntVec3 cell in cellRect)
            {
                if (!cell.IsForbidden(swimmer) && !cell.GetTerrain(map).IsWater&& cell.Standable(map))
                {
                    foreach (IntVec3 cell2 in GenAdjFast.AdjacentCellsCardinal(cell))
                    {
                        if (cell2.GetTerrain(map).HasModExtension <SwimmableWater>())
                        {
                            //Log.Message(swimmer.Name + " found shoreline at " + cell.x.ToString() + ", " + cell.z.ToString());
                            return(cell);
                        }
                    }
                }
            }
            return(root);
        }
예제 #17
0
        private void Update()
        {
            updateScheduled = false;
            var map = Find.CurrentMap;

            if (listening && map == null || Find.MapUI.designatorManager.SelectedDesignator != owningDesignator)
            {
                StopListening();
            }
            if (!listening)
            {
                return;
            }
            RegisterForNextUpdate();
            var dragger = Find.MapUI.designatorManager.Dragger;

            if (!SelectionInProgress && dragger.Dragging)
            {
                OnSelectionStarted();
            }
            else if (SelectionInProgress && !dragger.Dragging)
            {
                OnSelectionEnded();
            }
            if (SelectionInProgress)
            {
                var mouseCell   = UI.MouseCell();
                var currentCell = ClampPositionToMapRect(map, mouseCell);
                var currentRect = CellRect.FromLimits(SelectionStartCell, currentCell);
                if (currentRect != SelectedArea)
                {
                    SelectedArea = currentRect;
                    OnSelectedAreaChanged();
                }

                SelectionUpdate?.Invoke(SelectedArea);
            }
        }
        public OreNode(IntVec3 TR, IntVec3 DL, Map m, Color C, bool WithResource)
        {
            Size   = m.Size;
            Colour = C;


            boolGrid = new BoolGrid(m);

            Cells = CellRect.FromLimits(TR, DL).Cells.ToList <IntVec3>();



            if (WithResource)
            {
                this.AssignStone();
                this.AssignResource();
                this.AddToGrid();
            }
            else
            {
                this.RemoveFromGrid();
            }
        }
        private IEnumerator DoRendering(bool forceRenderFullMap = false)
        {
            yield return(new WaitForFixedUpdate());

            if (Rendering)
            {
                Log.Error("Progress Renderer is still rendering an image while a new rendering was requested. This can lead to missing or wrong data. (This can also happen in rare situations when you trigger manual rendering the exact same time as an automatic rendering happens. If you did that, just check your export folder if both renderings were done corrently and ignore this error.)");
            }
            Rendering = true;

            // Temporary switch to this map for rendering
            bool switchedMap   = false;
            Map  rememberedMap = Find.CurrentMap;

            if (map != rememberedMap)
            {
                switchedMap             = true;
                Current.Game.CurrentMap = map;
            }

            // Close world view if needed
            bool rememberedWorldRendered = WorldRendererUtility.WorldRenderedNow;

            if (rememberedWorldRendered)
            {
                CameraJumper.TryHideWorld();
            }

            // Calculate rendered area
            float startX = 0;
            float startZ = 0;
            float endX   = map.Size.x;
            float endZ   = map.Size.z;

            if (!forceRenderFullMap)
            {
                List <Designation> cornerMarkers = map.designationManager.allDesignations.FindAll(des => des.def == DesignationDefOf.CornerMarker);
                if (cornerMarkers.Count > 1)
                {
                    startX = endX;
                    startZ = endZ;
                    endX   = 0;
                    endZ   = 0;
                    foreach (Designation des in cornerMarkers)
                    {
                        IntVec3 cell = des.target.Cell;
                        if (cell.x < startX)
                        {
                            startX = cell.x;
                        }
                        if (cell.z < startZ)
                        {
                            startZ = cell.z;
                        }
                        if (cell.x > endX)
                        {
                            endX = cell.x;
                        }
                        if (cell.z > endZ)
                        {
                            endZ = cell.z;
                        }
                    }
                    endX += 1;
                    endZ += 1;
                }
            }

            // Only use smoothing when rendering was not triggered manually
            if (!manuallyTriggered)
            {
                // Test if target render area changed to reset smoothing
                if (rsTargetStartX != startX || rsTargetStartZ != startZ || rsTargetEndX != endX || rsTargetEndZ != endZ)
                {
                    // Check if area was manually reset or uninitialized (-1) to not smooth
                    if (rsTargetStartX == -1f && rsTargetStartZ == -1f && rsTargetEndX == -1f && rsTargetEndZ == -1f)
                    {
                        rsCurrentPosition = 1f;
                    }
                    else
                    {
                        rsCurrentPosition = 1f / (PRModSettings.smoothRenderAreaSteps + 1);
                    }
                    rsOldStartX    = rsTargetStartX;
                    rsOldStartZ    = rsTargetStartZ;
                    rsOldEndX      = rsTargetEndX;
                    rsOldEndZ      = rsTargetEndZ;
                    rsTargetStartX = startX;
                    rsTargetStartZ = startZ;
                    rsTargetEndX   = endX;
                    rsTargetEndZ   = endZ;
                }
                // Apply smoothing to render area
                if (rsCurrentPosition < 1f)
                {
                    startX             = rsOldStartX + (rsTargetStartX - rsOldStartX) * rsCurrentPosition;
                    startZ             = rsOldStartZ + (rsTargetStartZ - rsOldStartZ) * rsCurrentPosition;
                    endX               = rsOldEndX + (rsTargetEndX - rsOldEndX) * rsCurrentPosition;
                    endZ               = rsOldEndZ + (rsTargetEndZ - rsOldEndZ) * rsCurrentPosition;
                    rsCurrentPosition += 1f / (PRModSettings.smoothRenderAreaSteps + 1);
                }
            }

            float distX = endX - startX;
            float distZ = endZ - startZ;

            // Calculate basic values that are used for rendering
            int imageWidth;
            int imageHeight;

            if (PRModSettings.scaleOutputImage)
            {
                imageHeight = PRModSettings.outputImageFixedHeight;
                imageWidth  = (int)((float)imageHeight / distZ * distX);
            }
            else
            {
                imageWidth  = (int)(distX * PRModSettings.pixelPerCell);
                imageHeight = (int)(distZ * PRModSettings.pixelPerCell);
            }

            int renderCountX = (int)Math.Ceiling((float)imageWidth / RenderTextureSize);
            int renderCountZ = (int)Math.Ceiling((float)imageHeight / RenderTextureSize);
            int renderWidth  = (int)Math.Ceiling((float)imageWidth / renderCountX);
            int renderHeight = (int)Math.Ceiling((float)imageHeight / renderCountZ);

            float cameraPosX       = (float)distX / 2 / renderCountX;
            float cameraPosZ       = (float)distZ / 2 / renderCountZ;
            float orthographicSize = Math.Min(cameraPosX, cameraPosZ);

            orthographicSize = cameraPosZ;
            Vector3 cameraBasePos = new Vector3(cameraPosX, 15f + (orthographicSize - 11f) / 49f * 50f, cameraPosZ);

            RenderTexture renderTexture = RenderTexture.GetTemporary(renderWidth, renderHeight, 24);

            imageTexture = new Texture2D(imageWidth, imageHeight, TextureFormat.RGB24, false);

            Camera       camera    = Find.Camera;
            CameraDriver camDriver = camera.GetComponent <CameraDriver>();

            camDriver.enabled = false;

            // Store current camera data
            Vector3 rememberedRootPos      = map.rememberedCameraPos.rootPos;
            float   rememberedRootSize     = map.rememberedCameraPos.rootSize;
            float   rememberedFarClipPlane = camera.farClipPlane;

            // Overwrite current view rect in the camera driver
            CellRect camViewRect       = camDriver.CurrentViewRect;
            int      camRectMinX       = Math.Min((int)startX, camViewRect.minX);
            int      camRectMinZ       = Math.Min((int)startZ, camViewRect.minZ);
            int      camRectMaxX       = Math.Max((int)Math.Ceiling(endX), camViewRect.maxX);
            int      camRectMaxZ       = Math.Max((int)Math.Ceiling(endZ), camViewRect.maxZ);
            Traverse camDriverTraverse = Traverse.Create(camDriver);

            camDriverTraverse.Field("lastViewRect").SetValue(CellRect.FromLimits(camRectMinX, camRectMinZ, camRectMaxX, camRectMaxZ));
            camDriverTraverse.Field("lastViewRectGetFrame").SetValue(Time.frameCount);
            yield return(new WaitForEndOfFrame());

            // Set camera values needed for rendering
            camera.orthographicSize = orthographicSize;
            camera.farClipPlane     = cameraBasePos.y + 6.5f;

            // Create a temporary camera for rendering

            /*Camera tmpCam = Camera.Instantiate(camera);
             * tmpCam.orthographicSize = orthographicSize;
             * tmpCam.farClipPlane = cameraPos.y + 6.5f;*/

            // Set render textures
            //tmpCam.targetTexture = renderTexture;
            camera.targetTexture = renderTexture;
            RenderTexture.active = renderTexture;

            // Render the image texture
            try
            {
                if (PRModSettings.renderWeather)
                {
                    map.weatherManager.DrawAllWeather();
                }
                for (int i = 0; i < renderCountZ; i++)
                {
                    for (int j = 0; j < renderCountX; j++)
                    {
                        camera.transform.position = new Vector3(startX + cameraBasePos.x * (2 * j + 1), cameraBasePos.y, startZ + cameraBasePos.z * (2 * i + 1));
                        camera.Render();
                        imageTexture.ReadPixels(new Rect(0, 0, renderWidth, renderHeight), renderWidth * j, renderHeight * i, false);
                    }
                }
            } catch (Exception e)
            {
                Log.Error(e.Message, true);
            }

            // Restore camera and viewport
            RenderTexture.active = null;
            //tmpCam.targetTexture = null;
            camera.targetTexture = null;
            camera.farClipPlane  = rememberedFarClipPlane;
            camDriver.SetRootPosAndSize(rememberedRootPos, rememberedRootSize);
            camDriver.enabled = true;

            RenderTexture.ReleaseTemporary(renderTexture);

            // Switch back to world view if needed
            if (rememberedWorldRendered)
            {
                CameraJumper.TryShowWorld();
            }

            // Switch back to remembered map if needed
            if (switchedMap)
            {
                Current.Game.CurrentMap = rememberedMap;
            }

            // Sinal finished rendering
            Rendering = false;
            yield return(null);

            // Start encoding
            DoEncoding();

            yield break;
        }
예제 #20
0
 public Stencil Bound(int x1, int z1, int x2, int z2)
 {
     return(BoundTo(CellRect.FromLimits(Coords(x1, z1), Coords(x2, z2))));
 }
        public override void Resolve(ResolveParams rp)
        {
            Map      map      = BaseGen.globalSettings.map;
            CellRect cellRect = CellRect.Empty;

            RimWorld.SketchGen.ResolveParams parms = default(RimWorld.SketchGen.ResolveParams);
            parms.sketch              = new Sketch();
            parms.monumentOpen        = false;
            parms.monumentSize        = new IntVec2(rp.rect.Width, rp.rect.Height);
            parms.allowMonumentDoors  = false;
            parms.allowWood           = false;
            parms.allowFlammableWalls = false;
            if (rp.allowedMonumentThings != null)
            {
                parms.allowedMonumentThings = rp.allowedMonumentThings;
            }
            else
            {
                parms.allowedMonumentThings = new ThingFilter();
                parms.allowedMonumentThings.SetAllowAll(null, includeNonStorable: true);
            }
            parms.allowedMonumentThings.SetAllow(ThingDefOf.Drape, allow: false);
            Sketch sketch = RimWorld.SketchGen.SketchGen.Generate(SketchResolverDefOf.Monument, parms);

            sketch.Spawn(map, rp.rect.CenterCell, null, Sketch.SpawnPosType.Unchanged, Sketch.SpawnMode.Normal, wipeIfCollides: true, clearEdificeWhereFloor: true, null, dormant: false, buildRoofsInstantly: true);
            CellRect rect = SketchGenUtility.FindBiggestRect(sketch, (IntVec3 x) => sketch.TerrainAt(x) != null && !sketch.ThingsAt(x).Any((SketchThing y) => y.def == ThingDefOf.Wall)).MovedBy(rp.rect.CenterCell);

            for (int i = 0; i < sketch.Things.Count; i++)
            {
                if (sketch.Things[i].def == ThingDefOf.Wall)
                {
                    IntVec3 c = sketch.Things[i].pos + rp.rect.CenterCell;
                    cellRect = ((!cellRect.IsEmpty) ? CellRect.FromLimits(Mathf.Min(cellRect.minX, c.x), Mathf.Min(cellRect.minZ, c.z), Mathf.Max(cellRect.maxX, c.x), Mathf.Max(cellRect.maxZ, c.z)) : CellRect.SingleCell(c));
                }
            }
            if (!rect.IsEmpty)
            {
                ResolveParams resolveParams = rp;
                resolveParams.rect = rect;
                if (rp.allowedMonumentThings != null)
                {
                    resolveParams.allowedMonumentThings = rp.allowedMonumentThings;
                }
                else
                {
                    resolveParams.allowedMonumentThings = new ThingFilter();
                    resolveParams.allowedMonumentThings.SetAllowAll(null, includeNonStorable: true);
                }
                if (ModsConfig.RoyaltyActive)
                {
                    resolveParams.allowedMonumentThings.SetAllow(ThingDefOf.Drape, allow: false);
                }
                BaseGen.symbolStack.Push("interior_ancientTemple", resolveParams);
            }
            if (rp.makeWarningLetter.HasValue && rp.makeWarningLetter.Value)
            {
                int    nextSignalTagID  = Find.UniqueIDsManager.GetNextSignalTagID();
                string signalTag        = "ancientTempleApproached-" + nextSignalTagID;
                SignalAction_Letter obj = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter);
                obj.signalTag = signalTag;
                obj.letter    = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.ThreatBig, new TargetInfo(cellRect.CenterCell, map));
                GenSpawn.Spawn(obj, cellRect.CenterCell, map);
                RectTrigger obj2 = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger);
                obj2.signalTag         = signalTag;
                obj2.Rect              = cellRect.ExpandedBy(1).ClipInsideMap(map);
                obj2.destroyIfUnfogged = true;
                GenSpawn.Spawn(obj2, cellRect.CenterCell, map);
            }
        }
예제 #22
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            switch (this.stage)
            {
            case ExecutingStage.ClearParameters:
                this.competitorTable = null;
                this.style           = null;
                this.roundNumbers    = null;
                this.sandBagChance   = null;
                this.wallChance      = null;
                this.raidScales.Clear();
                this.stage = ExecutingStage.PickingParameters;
                break;

            case ExecutingStage.PickingParameters:
                break;

            case ExecutingStage.CalculatingFights:
                this.fights.Clear();
                switch (this.competitorTable.Value)
                {
                case ChallengeType.AnotherFaction:
                    this.CalculateFights(this.toRaid[0], this.toRaid[1]);
                    break;

                case ChallengeType.AllOtherFactions:
                    foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                    {
                        this.CalculateFights(this.toRaid[0], faction);
                    }
                    break;

                case ChallengeType.AllCoreFactions:
                    foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                    {
                        if ((faction.def.defName == "Colony") ||
                            (faction.def.defName == "Spacer") ||
                            (faction.def.defName == "SpacerHostile") ||
                            (faction.def.defName == "Outlander") ||
                            (faction.def.defName == "Pirate") ||
                            (faction.def.defName == "Tribe") ||
                            (faction.def.defName == "Mechanoid"))
                        {
                            this.CalculateFights(this.toRaid[0], faction);
                        }
                    }
                    break;
                }
                this.stage = ExecutingStage.CreatingArena;
                break;

            case ExecutingStage.CreatingArena:

                if (this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).Any())
                {
                    this.currentFight = this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).First();
                }
                else
                {
                    this.stage = ExecutingStage.DisplaingResults;
                    return;
                }

                CellRect rect = CellRect.FromLimits(5, 5, 100, 60);

                rect.ClipInsideMap();

                foreach (IntVec3 current in rect)
                {
                    Find.RoofGrid.SetRoof(current, null);
                }

                foreach (IntVec3 current in rect)
                {
                    List <Thing> thingList = current.GetThingList();
                    for (int i = thingList.Count - 1; i >= 0; i--)
                    {
                        if (!Thing.allowDestroyNonDestroyable && !thingList[i].def.destroyable)
                        {
                            thingList[i].DeSpawn();
                        }
                        else
                        {
                            thingList[i].Destroy(DestroyMode.Vanish);
                        }
                    }

                    if (Rand.Range(0, 100) < this.sandBagChance.Value)
                    {
                        GenSpawn.Spawn(ThingDefOf.Sandbags, current);
                    }
                    else
                    if (Rand.Range(0, 100) < this.wallChance.Value)
                    {
                        ThingDef wall     = ThingDefOf.Wall;
                        Thing    newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                        GenSpawn.Spawn(newThing, current);
                    }
                }

                foreach (IntVec3 current in rect)
                {
                    Find.TerrainGrid.SetTerrain(current, TerrainDefOf.Concrete);
                }

                foreach (IntVec3 current in rect.EdgeCells)
                {
                    ThingDef wall     = ThingDefOf.Wall;
                    Thing    newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                    GenSpawn.Spawn(newThing, current);
                }

                AbilityRequeriment_ColonyBiggerThan.forcedValue = this.currentFight.points;

                this.currentFight.factionOne.SetHostileTo(this.currentFight.factionTwo, true);
                this.currentFight.factionOne.SetHostileTo(Faction.OfColony, true);
                this.currentFight.factionTwo.SetHostileTo(this.currentFight.factionOne, true);
                this.currentFight.factionTwo.SetHostileTo(Faction.OfColony, true);

                List <Brain> oldBrains = new List <Brain>(Find.SquadBrainManager.allSquadBrains);

                IncidentDef   incidentDef   = IncidentDef.Named("RaidEnemy");
                IncidentParms incidentParms = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                incidentParms.faction         = this.currentFight.factionOne;
                incidentParms.spawnCenter     = new IntVec3(30, 0, 35);
                incidentParms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
                incidentParms.points          = this.currentFight.points;
                incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                incidentDef.Worker.TryExecute(incidentParms);

                incidentDef                   = IncidentDef.Named("RaidEnemy");
                incidentParms                 = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                incidentParms.faction         = this.currentFight.factionTwo;
                incidentParms.spawnCenter     = new IntVec3(80, 0, 35);
                incidentParms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
                incidentParms.points          = this.currentFight.points;
                incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                incidentDef.Worker.TryExecute(incidentParms);

                List <Brain> newBrains = new List <Brain>(Find.SquadBrainManager.allSquadBrains);
                foreach (Brain b in oldBrains)
                {
                    newBrains.Remove(b);
                }

                this.currentBrain1  = this.GetBrain(this.currentFight.factionOne, newBrains);
                this.currentBrain2  = this.GetBrain(this.currentFight.factionTwo, newBrains);
                this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                this.remainingTicks = MapComponentFactionGauntlet.roundLenght;
                this.stage          = ExecutingStage.Fighting;
                break;

            case ExecutingStage.Fighting:

                this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                if ((this.currentPoints1 == 0.0f) ||
                    (this.currentPoints2 == 0.0f))
                {
                    this.EndFight();
                    return;
                }

                if (this.style.Value == FightStyle.TimedRounds)
                {
                    if (this.remainingTicks > 0)
                    {
                        this.remainingTicks--;
                    }
                    else
                    {
                        this.EndFight();
                        return;
                    }
                }

                break;

            case ExecutingStage.CleaningArena:
                this.remainingTicks--;
                if (this.remainingTicks <= 0)
                {
                    this.stage = ExecutingStage.CreatingArena;
                }
                break;
            }
        }
예제 #23
0
        private void FloorFillRoom_NewTmp(IntVec3 c, HashSet <IntVec3> walls, HashSet <IntVec3> visited, Sketch sketch, TerrainDef def1, TerrainDef def2, CellRect outerRect, bool singleFloorType)
        {
            if (visited.Contains(c))
            {
                return;
            }
            tmpCells.Clear();
            tmpStack.Clear();
            tmpStack.Push(new Pair <int, int>(c.x, c.z));
            visited.Add(c);
            int num  = c.x;
            int num2 = c.x;
            int num3 = c.z;
            int num4 = c.z;

            while (tmpStack.Count != 0)
            {
                Pair <int, int> pair   = tmpStack.Pop();
                int             first  = pair.First;
                int             second = pair.Second;
                tmpCells.Add(new IntVec3(first, 0, second));
                num  = Mathf.Min(num, first);
                num2 = Mathf.Max(num2, first);
                num3 = Mathf.Min(num3, second);
                num4 = Mathf.Max(num4, second);
                if (first > outerRect.minX && !walls.Contains(new IntVec3(first - 1, 0, second)) && !visited.Contains(new IntVec3(first - 1, 0, second)))
                {
                    visited.Add(new IntVec3(first - 1, 0, second));
                    tmpStack.Push(new Pair <int, int>(first - 1, second));
                }
                if (second > outerRect.minZ && !walls.Contains(new IntVec3(first, 0, second - 1)) && !visited.Contains(new IntVec3(first, 0, second - 1)))
                {
                    visited.Add(new IntVec3(first, 0, second - 1));
                    tmpStack.Push(new Pair <int, int>(first, second - 1));
                }
                if (first < outerRect.maxX && !walls.Contains(new IntVec3(first + 1, 0, second)) && !visited.Contains(new IntVec3(first + 1, 0, second)))
                {
                    visited.Add(new IntVec3(first + 1, 0, second));
                    tmpStack.Push(new Pair <int, int>(first + 1, second));
                }
                if (second < outerRect.maxZ && !walls.Contains(new IntVec3(first, 0, second + 1)) && !visited.Contains(new IntVec3(first, 0, second + 1)))
                {
                    visited.Add(new IntVec3(first, 0, second + 1));
                    tmpStack.Push(new Pair <int, int>(first, second + 1));
                }
            }
            for (int i = 0; i < tmpCells.Count; i++)
            {
                if (outerRect.IsOnEdge(tmpCells[i]))
                {
                    return;
                }
            }
            CellRect cellRect = CellRect.FromLimits(num, num3, num2, num4);

            bool[,] array = AbstractShapeGenerator.Generate(cellRect.Width, cellRect.Height, horizontalSymmetry: true, verticalSymmetry: true);
            for (int j = 0; j < tmpCells.Count; j++)
            {
                IntVec3 pos = tmpCells[j];
                if (!sketch.ThingsAt(pos).Any((SketchThing x) => x.def.passability == Traversability.Impassable && x.def.Fillage == FillCategory.Full))
                {
                    if (array[pos.x - cellRect.minX, pos.z - cellRect.minZ] || singleFloorType)
                    {
                        sketch.AddTerrain(def1, pos, wipeIfCollides: false);
                    }
                    else
                    {
                        sketch.AddTerrain(def2, pos, wipeIfCollides: false);
                    }
                }
            }
        }
예제 #24
0
        public void TakeStep()
        {
            drawTracks.Clear();
            foreach (VehicleTrack track in Props.tracks)
            {
                IntVec2 rotationalSign = new IntVec2(1, 1);

                if (ParentVehicle.Rotation == Rot4.South)
                {
                    rotationalSign.z = -1;
                }
                else if (ParentVehicle.Rotation == Rot4.West)
                {
                    rotationalSign.x = -1;
                }
                else if (ParentVehicle.Rotation == Rot4.East)
                {
                    rotationalSign.z = -1;
                }

                IntVec2 start = track.trackPoint.First;
                IntVec2 end   = track.trackPoint.Second;
                start.z -= 1;
                end.z   -= 1;

                int     xFirst  = rotationalSign.x * (ParentVehicle.Rotation.IsHorizontal ? start.z : start.x);
                int     zFirst  = rotationalSign.z * (ParentVehicle.Rotation.IsHorizontal ? start.x : start.z);
                IntVec3 first   = new IntVec3(ParentVehicle.Position.x - xFirst, ParentVehicle.Position.y, ParentVehicle.Position.z - zFirst);
                int     xSecond = rotationalSign.x * (ParentVehicle.Rotation.IsHorizontal ? end.z : end.x);
                int     zSecond = rotationalSign.z * (ParentVehicle.Rotation.IsHorizontal ? end.x : end.z);
                IntVec3 second  = new IntVec3(ParentVehicle.Position.x - xSecond, ParentVehicle.Position.y, ParentVehicle.Position.z - zSecond);

                drawTracks.Add(new Pair <IntVec3, IntVec3>(first, second));

                foreach (IntVec3 cell in CellRect.FromLimits(first, second).Cells)
                {
                    if (!cell.InBounds(ParentVehicle.Map))
                    {
                        continue;
                    }

                    List <Thing> things = ParentVehicle.Map.thingGrid.ThingsListAtFast(cell);
                    for (int i = things.Count - 1; i >= 0; i--)
                    {
                        Thing thing = things[i];
                        if (thing == ParentVehicle)
                        {
                            continue;
                        }
                        if (track.destroyableCategories.Contains(thing.def.category))
                        {
                            try
                            {
                                if (thing.def.category == ThingCategory.Pawn)
                                {
                                    thing.TakeDamage(new DamageInfo(DamageDefOf.Crush, 200));
                                }
                                else
                                {
                                    thing.Destroy();
                                }
                            }
                            catch
                            {
                                //do nothing right now
                            }
                        }
                    }
                }

                foreach (IntVec3 cell in WarningRect().Cells)
                {
                    if (!cell.InBounds(ParentVehicle.Map))
                    {
                        continue;
                    }
                    if (ParentVehicle.Map.thingGrid.ThingsListAtFast(cell).Any(t => t is Pawn))
                    {
                        GenVehicleTracks.NotifyNearbyPawnsPathOfVehicleTrack(ParentVehicle);
                    }
                }
            }
        }