public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!c.InBounds(base.Map))
            {
                return(false);
            }
            if (base.Map.designationManager.DesignationAt(c, this.Designation) != null)
            {
                return(AcceptanceReport.WasRejected);
            }
            if (c.Fogged(base.Map))
            {
                return(true);
            }
            Mineable firstMineable = c.GetFirstMineable(base.Map);

            if (firstMineable == null)
            {
                return("MessageMustDesignateMineable".Translate());
            }
            AcceptanceReport result = this.CanDesignateThing(firstMineable);

            if (!result.Accepted)
            {
                return(result);
            }
            return(AcceptanceReport.WasAccepted);
        }
Ejemplo n.º 2
0
        private bool IsClear(IntVec3 c, Map map)
        {
            if (!c.GetTerrain(map).affordances.Contains(TerrainAffordanceDefOf.Heavy))
            {
                return(false);
            }
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i].def.IsBuildingArtificial && thingList[i].Faction == Faction.OfPlayer)
                {
                    return(false);
                }
                if (!thingList[i].def.mineable)
                {
                    continue;
                }
                bool flag = false;
                for (int j = 0; j < 8; j++)
                {
                    IntVec3 c2 = c + GenAdj.AdjacentCells[j];
                    if (c2.InBounds(map) && c2.GetFirstMineable(map) == null)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
        public void incrementSeen(Faction faction, int[] factionShownCells, int idx)
        {
            if ((++factionShownCells[idx] == 1) && faction.IsPlayer)
            {
                IntVec3 cell = idxToCellCache[idx];

                knownCells[idx] = true;

                Designation designation = designationManager.DesignationAt(cell, DesignationDefOf.Mine);
                if (designation != null && cell.GetFirstMineable(map) == null)
                {
                    designation.Delete();
                }

                if (initialized)
                {
                    mapDrawer.MapMeshDirty(cell, SectionLayer_FoVLayer.mapMeshFlag, true, false);
                }

                List <CompHideFromPlayer> comps = compHideFromPlayerGrid[idx];
                int compCount = comps.Count;
                for (int i = 0; i < compCount; i++)
                {
                    comps[i].updateVisibility(true);
                }
            }
        }
Ejemplo n.º 4
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!c.InBounds(map: Find.CurrentMap))
            {
                return(AcceptanceReport.WasRejected);
            }
            if (Find.CurrentMap.designationManager.DesignationAt(c: c, def: DesignationDefOf.Plan) == null)
            {
                return(AcceptanceReport.WasRejected);
            }
            if (c.Fogged(map: Find.CurrentMap))
            {
                return(AcceptanceReport.WasAccepted);
            }
            Thing thing = c.GetFirstMineable(map: Find.CurrentMap);

            if (thing == null)
            {
                return("MessageMustDesignateMineable".Translate());
            }
            AcceptanceReport result = this.CanDesignateThing(t: thing);

            if (!result.Accepted)
            {
                return(result);
            }
            return(AcceptanceReport.WasAccepted);
        }
        public void revealCell(int idx)
        {
            if (!knownCells[idx])
            {
                ref IntVec3 cell = ref idxToCellCache[idx];

                knownCells[idx] = true;

                Designation designation = mineDesignationGrid[idx];
                if (designation != null && cell.GetFirstMineable(map) == null)
                {
                    designation.Delete();
                }

                if (initialized)
                {
                    setMapMeshDirtyFlag(idx);
                }

                if (compHideFromPlayerGridCount[idx] != 0)
                {
                    List <CompHideFromPlayer> comps = compHideFromPlayerGrid[idx];
                    int compCount = comps.Count;
                    for (int i = 0; i < compCount; i++)
                    {
                        comps[i].updateVisibility(true);
                    }
                }
            }
Ejemplo n.º 6
0
    public override AcceptanceReport CanDesignateCell(IntVec3 c)
    {
        if (!c.InBounds(Map))
        {
            return(false);
        }

        if (Map.designationManager.DesignationAt(c, Designation) != null)
        {
            return(AcceptanceReport.WasRejected);
        }

        if (Map.designationManager.DesignationAt(c, MineDesig) != null)
        {
            return(AcceptanceReport.WasRejected);
        }

        if (c.Fogged(Map))
        {
            return(false);
        }

        var firstMineable = c.GetFirstMineable(Map);

        if (firstMineable == null)
        {
            return("MessageMustDesignateMineable".Translate());
        }

        var result = CanDesignateThing(firstMineable);

        if (!result.Accepted)
        {
            return(result);
        }

        var chkcells = GenAdjFast.AdjacentCellsCardinal(c);
        var entry    = false;

        if (chkcells.Count > 0)
        {
            foreach (var chkcell in chkcells)
            {
                if (!chkcell.InBounds(Map) || !chkcell.Standable(Map) && !chkcell.Walkable(Map))
                {
                    continue;
                }

                entry = true;
                break;
            }
        }

        if (!entry)
        {
            return(false);
        }

        return(AcceptanceReport.WasAccepted);
    }
Ejemplo n.º 7
0
 public override void DesignateSingleCell(IntVec3 loc)
 {
     base.Map.designationManager.AddDesignation(new Designation(loc, Designation));
     base.Map.designationManager.TryRemoveDesignation(loc, DesignationDefOf.SmoothWall);
     if (DebugSettings.godMode)
     {
         loc.GetFirstMineable(base.Map)?.DestroyMined(null);
     }
 }
Ejemplo n.º 8
0
        private bool CellIsMineable(Map map, IntVec3 c)
        {
            if (c.Fogged(map))
            {
                return(true);
            }
            var m = c.GetFirstMineable(map);

            return(m != null && m.def.mineable);
        }
Ejemplo n.º 9
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            AcceptanceReport result;

            if (!c.InBounds(base.Map))
            {
                result = false;
            }
            else if (base.Map.designationManager.DesignationAt(c, this.Designation) != null)
            {
                result = AcceptanceReport.WasRejected;
            }
            else if (c.Fogged(base.Map))
            {
                result = true;
            }
            else
            {
                Mineable firstMineable = c.GetFirstMineable(base.Map);
                if (firstMineable == null)
                {
                    result = "MessageMustDesignateMineable".Translate();
                }
                else
                {
                    AcceptanceReport acceptanceReport = this.CanDesignateThing(firstMineable);
                    if (!acceptanceReport.Accepted)
                    {
                        result = acceptanceReport;
                    }
                    else
                    {
                        result = AcceptanceReport.WasAccepted;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 10
0
        /*
         * // Token: 0x0600368B RID: 13963 RVA: 0x001A0E1C File Offset: 0x0019F21C
         * public static bool TryFindCell(out IntVec3 cell, out IntVec3 locationC, Map map, bool allowFogged = true)
         * {
         *  ThingDef namedA = XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon;
         *  ThingDef namedB = XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon;
         *  InfestationLikeCellFinder.CalculateLocationCandidates(map, allowFogged);
         *  Predicate<IntVec3> validator = delegate (IntVec3 y)
         *  {
         *      bool score = InfestationLikeCellFinder.GetScoreAt(y, map, allowFogged) > 0f;
         *      bool XenohiveA = y.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive) == null;
         *      bool XenohiveB = y.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive_Child) == null;
         *      bool filled = y.Filled(map);
         *      bool edifice = y.GetEdifice(map).DestroyedOrNull();
         *      bool building = y.GetFirstBuilding(map).DestroyedOrNull();
         *      bool thingA = y.GetFirstThing(map, namedA).DestroyedOrNull();
         *      bool thingB = y.GetFirstThing(map, namedB).DestroyedOrNull();
         *  //    Log.Message(string.Format("Cell: {0}, score: {1}, XenohiveA: {2}, XenohiveB: {3}, !filled: {4}, edifice: {5}, building: {6}, thingA: {7}, thingB: {8}\nResult: {9}", y, GetScoreAt(y, map, allowFogged), XenohiveA, XenohiveB, !filled, edifice, building, thingA, thingB, score && XenohiveA && XenohiveB && !filled && edifice && building && thingA && thingB));
         *      return score && XenohiveA && XenohiveB && !filled && edifice && building && thingA && thingB;
         *  };
         *  if (!InfestationLikeCellFinder.locationCandidates.TryRandomElementByWeight((InfestationLikeCellFinder.LocationCandidate x) => x.score, out LocationCandidate locationCandidate))
         *  {
         *      cell = IntVec3.Invalid;
         *      locationC = IntVec3.Invalid;
         *      if (!InfestationCellFinder.TryFindCell(out cell, map))
         *      {
         *          cell = IntVec3.Invalid;
         *          return false;
         *      }
         *  }
         *  locationC = locationCandidate.cell;
         *  cell = CellFinder.FindNoWipeSpawnLocNear(locationCandidate.cell, map, XenomorphDefOf.RRY_XenomorphHive, Rot4.North, 2, (IntVec3 x) => InfestationLikeCellFinder.GetScoreAt(x, map, allowFogged) > 0f && x.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive) == null && x.GetFirstThing(map, OGHiveLikeDefOf.TunnelHiveLikeSpawner) == null && x.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon) == null && x.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon) == null);
         *  ThingDef td = XenomorphDefOf.RRY_Hive_Slime;
         *  GenSpawn.Spawn(td, cell, map);
         *  return true;
         * }
         */
        // Token: 0x0600368C RID: 13964 RVA: 0x001A0EAC File Offset: 0x0019F2AC
        public static float GetScoreAt(IntVec3 cell, Map map, bool allowFogged = false, bool allowUnroofed = false, bool allowDigging = false)
        {
            if (cell.GetTerrain(map).HasTag("Water") || cell.GetTerrain(map).defName.Contains("Water") || cell.GetTerrain(map).defName.Contains("Marsh"))
            {
                return(0f);
            }
            if ((!cell.Walkable(map) && !cell.GetFirstMineable(map).DestroyedOrNull() && !allowDigging))
            {
                return(0f);
            }
            if (cell.Fogged(map) && !allowFogged)
            {
                return(0f);
            }
            if (InfestationLikeCellFinder.CellHasBlockingThings(cell, map) && !allowDigging)
            {
                return(0f);
            }
            if ((!cell.Roofed(map) || !cell.GetRoof(map).isThickRoof) && !allowUnroofed)
            {
                return(0f);
            }
            Region region = cell.GetRegion(map, RegionType.Set_Passable);

            if (region == null && !allowDigging)
            {
                return(0f);
            }
            if (InfestationLikeCellFinder.closedAreaSize[cell] < 2 && !allowDigging)
            {
                return(0f);
            }
            float temperature = cell.GetTemperature(map);

            if (temperature < -40f)
            {
                return(0f);
            }
            float mountainousnessScoreAt = InfestationLikeCellFinder.GetMountainousnessScoreAt(cell, map);

            //    Log.Message(String.Format("{0} mountainousnessScoreAt: {1}", cell, mountainousnessScoreAt), true);
            if (mountainousnessScoreAt < (allowDigging ? 0.5f : 0.17f))
            {
                //    Log.Message(String.Format("{0} faield due to Low Mountainousness Score",cell), true);
                return(0f);
            }
            int   num = InfestationLikeCellFinder.StraightLineDistToUnroofed(cell, map);
            float num2;

            if (region == null)
            {
                num2 = (float)num * 1.15f;
            }
            else
            {
                if (!InfestationLikeCellFinder.regionsDistanceToUnroofed.TryGetValue(region, out num2))
                {
                    num2 = (float)num * 1.15f;
                }
                else
                {
                    num2 = Mathf.Min(num2, (float)num * 4f);
                }
            }
            num2 = Mathf.Pow(num2, 1.55f);
            float num3 = Mathf.InverseLerp(0f, 12f, (float)num);
            float num4 = Mathf.Lerp(1f, 0.18f, map.glowGrid.GameGlowAt(cell, false));
            float num5 = 1f - Mathf.Clamp(InfestationLikeCellFinder.DistToBlocker(cell, map) / 11f, 0f, 0.6f);
            float num6 = Mathf.InverseLerp(-17f, -7f, temperature);
            float num7 = num2 * num3 * num5 * mountainousnessScoreAt * num4 * num6;

            num7 = Mathf.Pow(num7, 1.2f);
            if (num7 < 7.5f)
            {
                return(0f);
            }
            if ((float)InfestationLikeCellFinder.distToColonyBuilding[cell] < 20f)
            {
                num7 = (int)(num7 * 0.75f);
            }
            if (map.areaManager.Home[cell])
            {
                num7 = (int)(num7 * 0.75f);
            }
            return(num7);
        }
Ejemplo n.º 11
0
        public override void DesignateSingleCell(IntVec3 loc)
        {
            var originalLocRoof = Map.roofGrid.RoofAt(loc);
            // tiles are added to a queue to ensure we process closer tiles first
            var locQueue = new Queue <IntVec3>();
            // remember every tile we have queued, to avoid duplicating effort
            var locQueued = new HashSet <IntVec3>();

            locQueue.Enqueue(loc);
            locQueued.Add(loc);

            var numDesignated = 0;

            while (locQueue.Count > 0 && numDesignated < 1201)
            {
                // Log.Message("Deqeueing " + loc.ToString());
                loc = locQueue.Dequeue();

                // Log.Message("getting locThing");
                Thing locThing = loc.GetFirstMineable(Map);
                // Log.Message("checking locThing==null");
                if (locThing == null)
                {
                    continue;
                }

                // Log.Message("checking CanDesignateThing");
                if (!CanDesignateThing(locThing).Accepted)
                {
                    continue;
                }

                // Log.Message("getting locRoof");
                var locRoof = Map.roofGrid.RoofAt(loc);
                // Log.Message("checking one null roof");
                if (locRoof == null && originalLocRoof != null ||
                    locRoof != null && originalLocRoof == null)
                {
                    continue;
                }

                // Log.Message("checking roof defNames match");
                if (locRoof != null &&
                    locRoof.defName != originalLocRoof.defName)
                {
                    continue;
                }

                // Log.Message("checking DesignationAt");
                if (Map.designationManager.DesignationAt(loc, DesignationDefOf.Mine) != null)
                {
                    continue;
                }

                // Log.Message("Designating " + loc.ToString());
                base.DesignateSingleCell(loc);
                numDesignated++;

                foreach (var newLoc in GenAdjFast.AdjacentCellsCardinal(loc))
                {
                    if (!newLoc.InBounds(Map))
                    {
                        continue;
                    }

                    if (locQueued.Contains(newLoc))
                    {
                        continue;
                    }

                    // Log.Message("Enqueueing " + newLoc.ToString());
                    locQueue.Enqueue(newLoc);
                    locQueued.Add(newLoc);
                }
            }
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing otherThing = null)
        {
            TerrainDef terrainDef = map.terrainGrid.TerrainAt(loc);

            if (terrainDef.defName.Contains("Bridge"))
            {
                return(new AcceptanceReport("RAB.NoFloorOnBridge".Translate()));
            }
            Thing thing = loc.GetFirstMineable(map);

            if (thing != null)
            {
                return("RAB.NoFloorOnBridge".Translate());
            }
            List <Thing> things = map.thingGrid.ThingsListAtFast(loc);

            for (int k = 0; k < things.Count; k++)
            {
                if (things[k] != thingToIgnore)
                {
                    if (things[k].def.defName.Contains("RBB_") || things[k].def.defName.Contains("Wall"))
                    {
                        return(new AcceptanceReport("RAB.NoFloorOnBridge".Translate()));
                    }
                }
            }
            if (terrainDef.defName.Equals("MarshyTerrain") || terrainDef.defName.Equals("Mud"))
            {
                return(true);
            }
            bool waterNear = false;

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    int     x            = loc.x + i;
                    int     z            = loc.z + j;
                    IntVec3 newSpot      = new IntVec3(x, 0, z);
                    string  terrainCheck = map.terrainGrid.TerrainAt(newSpot).defName;
                    if (terrainCheck.Contains("Water") || terrainCheck.Equals("Marsh") || terrainCheck.Contains("BridgeMarsh") || terrainCheck.Contains("Mud") || terrainCheck.Contains("MarshyTerrain"))
                    {
                        waterNear = true;
                        break;
                    }
                }
            }
            if (waterNear)
            {
                for (int i = -2; i < 3; i++)
                {
                    for (int j = -2; j < 3; j++)
                    {
                        int     x            = loc.x + i;
                        int     z            = loc.z + j;
                        IntVec3 newSpot      = new IntVec3(x, 0, z);
                        string  terrainCheck = map.terrainGrid.TerrainAt(newSpot).defName;
                        if (terrainCheck.Contains("Water") || terrainCheck.Equals("Marsh") || terrainCheck.Contains("BridgeMarsh") || terrainCheck.Contains("Mud") || terrainCheck.Contains("MarshyTerrain"))
                        {
                            waterNear = true;
                            break;
                        }
                    }
                }
            }
            if (waterNear)
            {
                for (int i = -3; i < 4; i++)
                {
                    for (int j = -3; j < 4; j++)
                    {
                        int     x            = loc.x + i;
                        int     z            = loc.z + j;
                        IntVec3 newSpot      = new IntVec3(x, 0, z);
                        string  terrainCheck = map.terrainGrid.TerrainAt(newSpot).defName;
                        if (terrainCheck.Contains("Water") || terrainCheck.Equals("Marsh") || terrainCheck.Contains("BridgeMarsh") || terrainCheck.Contains("Mud") || terrainCheck.Contains("MarshyTerrain"))
                        {
                            waterNear = true;
                            break;
                        }
                    }
                }
            }
            if (waterNear)
            {
                return(true);
            }
            return(new AcceptanceReport("RAB.Boardwalk".Translate()));
        }