示例#1
0
 public static bool OpenRoofCountStopAt(District __instance, ref int __result, int threshold)
 {
     lock (__instance) //added
     {
         if (__instance.cachedOpenRoofCount == -1 && __instance.cachedOpenRoofState == null)
         {
             __instance.cachedOpenRoofCount = 0;
             __instance.cachedOpenRoofState = __instance.Cells.GetEnumerator();
         }
         if (__instance.cachedOpenRoofCount < threshold && __instance.cachedOpenRoofState != null)
         {
             RoofGrid roofGrid = __instance.Map.roofGrid;
             while (__instance.cachedOpenRoofCount < threshold && __instance.cachedOpenRoofState.MoveNext())
             {
                 if (!roofGrid.Roofed(__instance.cachedOpenRoofState.Current))
                 {
                     ++__instance.cachedOpenRoofCount;
                 }
             }
             if (__instance.cachedOpenRoofCount < threshold)
             {
                 __instance.cachedOpenRoofState = null;
             }
         }
         __result = __instance.cachedOpenRoofCount;
     }
     return(false);
 }
        public static void MakeTriangularRoom(Map map, ResolveParams rp)
        {
            if (rp.wallStuff == null)
            {
                Faction faction = Find.FactionManager.RandomNonHostileFaction(false, false, true, TechLevel.Spacer);

                rp.wallStuff = BaseGenUtility.RandomCheapWallStuff(faction, false);
            }
            if (rp.floorDef == null)
            {
                rp.floorDef = BaseGenUtility.CorrespondingTerrainDef(rp.wallStuff, true);
            }
            if (rp.floorDef == null)
            {
                rp.floorDef = BaseGenUtility.RandomBasicFloorDef(Faction.OfMechanoids, false);
            }
            ResolveParams resolveParams = rp;

            resolveParams.rect = new CellRect(rp.rect.minX, rp.rect.minZ, 1, rp.rect.Height);
            BaseGen.symbolStack.Push("edgeWalls", resolveParams, null);
            for (int i = 0; i <= rp.rect.Width; i++)
            {
                int num  = rp.rect.minX + i;
                int num2 = (int)Math.Floor((double)(0.5f * (float)i));
                int num3 = (int)Math.Ceiling((double)(0.5f * (float)i));
                for (int j = rp.rect.minZ + num2; j < rp.rect.minZ + rp.rect.Width - num2; j++)
                {
                    foreach (Thing thing in map.thingGrid.ThingsAt(new IntVec3(num, 1, j)))
                    {
                        thing.TakeDamage(new DamageInfo(DamageDefOf.Blunt, 10000, -1f, -1f, null, null, null, 0));
                    }
                    MapGenUtility.TryToSetFloorTile(new IntVec3(num, 1, j), map, rp.floorDef);
                    if (j == rp.rect.minZ + num2 || j == rp.rect.minZ + num3 || j == rp.rect.minZ + rp.rect.Width - (num2 + 1) || j == rp.rect.minZ + rp.rect.Width - (num3 + 1))
                    {
                        ResolveParams resolveParams2 = rp;
                        resolveParams2.rect = new CellRect(num, j, 1, 1);
                        BaseGen.symbolStack.Push("edgeWalls", resolveParams2, null);
                    }
                }
            }
            map.MapUpdate();
            RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
            RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;

            for (int k = 0; k <= rp.rect.Width; k++)
            {
                int newX = rp.rect.minX + k;
                int num4 = (int)Math.Floor((double)(0.5f * (float)k));
                for (int l = rp.rect.minZ + num4; l < rp.rect.minZ + rp.rect.Width - num4; l++)
                {
                    IntVec3 c = new IntVec3(newX, 1, l);
                    if (!roofGrid.Roofed(c))
                    {
                        roofGrid.SetRoof(c, def);
                    }
                }
            }
        }
 public override void Resolve(ResolveParams rp)
 {
     if (!rp.noRoof.HasValue || !rp.noRoof.Value)
     {
         RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
         RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;
         foreach (IntVec3 item in rp.rect)
         {
             if (!roofGrid.Roofed(item))
             {
                 roofGrid.SetRoof(item, def);
             }
         }
     }
 }
 public override void Resolve(ResolveParams rp)
 {
     if (rp.noRoof == null || !rp.noRoof.Value)
     {
         RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
         RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;
         CellRect.CellRectIterator iterator = rp.rect.GetIterator();
         while (!iterator.Done())
         {
             IntVec3 c = iterator.Current;
             if (!roofGrid.Roofed(c))
             {
                 roofGrid.SetRoof(c, def);
             }
             iterator.MoveNext();
         }
     }
 }
示例#5
0
 public static bool OpenRoofCountStopAt(Room __instance, ref int __result, int threshold)
 {
     //IEnumerator<IntVec3> cachedOpenRoofState2 = __instance.Cells.GetEnumerator();
     //int cachedOpenRoofCount2 = -1;
     lock (__instance)
     {
         if (cachedOpenRoofCount(__instance) == -1 && cachedOpenRoofState(__instance) == null)
         {
             cachedOpenRoofCount(__instance) = 0;
             cachedOpenRoofState(__instance) = __instance.Cells.GetEnumerator();
         }
         if (cachedOpenRoofCount(__instance) < threshold && cachedOpenRoofState(__instance) != null)
         {
             RoofGrid roofGrid = __instance.Map.roofGrid;
             if (null != roofGrid)
             {
                 while (cachedOpenRoofCount(__instance) < threshold && cachedOpenRoofState(__instance).MoveNext())
                 {
                     IntVec3 currentRoofState = cachedOpenRoofState(__instance).Current;
                     if (null != currentRoofState)
                     {
                         if (!roofGrid.Roofed(currentRoofState))
                         {
                             cachedOpenRoofCount(__instance)++;
                         }
                     }
                 }
                 if (cachedOpenRoofCount(__instance) < threshold)
                 {
                     cachedOpenRoofState(__instance) = null;
                 }
             }
         }
         __result = cachedOpenRoofCount(__instance);
     }
     return(false);
 }
        public float calcPawnSightRange(IntVec3 position, bool forTargeting, bool shouldMove)
        {
            if (pawn == null)
            {
                Log.Error("calcPawnSightRange performed on non pawn thing");
                return(0);
            }

            float sightRange = 0f;

            initMap();

            bool sleeping = !isMechanoid && pawn.CurJob != null && pawn.jobs.curDriver.asleep;

            if (!shouldMove && !sleeping && (pawnPather == null || !pawnPather.Moving))
            {
                Verb attackVerb = null;
                if (pawn.CurJob != null)
                {
                    JobDef jobDef = pawn.CurJob.def;
                    if (jobDef == JobDefOf.ManTurret)
                    {
                        Building_Turret mannedTurret = pawn.CurJob.targetA.Thing as Building_Turret;
                        if (mannedTurret != null)
                        {
                            attackVerb = mannedTurret.AttackVerb;
                        }
                    }
                    else if (jobDef == JobDefOf.AttackStatic || jobDef == JobDefOf.AttackMelee || jobDef == JobDefOf.WaitCombat || jobDef == JobDefOf.Hunt)
                    {
                        if (pawn.equipment != null)
                        {
                            ThingWithComps primary = pawn.equipment.Primary;
                            if (primary != null && primary.def.IsRangedWeapon)
                            {
                                attackVerb = primary.GetComp <CompEquippable>().PrimaryVerb;
                            }
                        }
                    }
                }

                if (attackVerb != null && attackVerb.verbProps.range > baseViewRange && attackVerb.verbProps.requireLineOfSight && attackVerb.ownerEquipment.def.IsRangedWeapon)
                {
                    float attackVerbRange = attackVerb.verbProps.range;
                    if (baseViewRange < attackVerbRange)
                    {
                        int ticksStanding = Find.TickManager.TicksGame - lastMovementTick;

                        float statValue     = pawn.GetStatValue(StatDefOf.AimingDelayFactor, true);
                        int   ticksToSearch = (attackVerb.verbProps.warmupTime * statValue).SecondsToTicks() * Mathf.RoundToInt((attackVerbRange - baseViewRange) / 2);

                        if (ticksStanding >= ticksToSearch)
                        {
                            sightRange = attackVerbRange * capacities.GetLevel(PawnCapacityDefOf.Sight);
                        }
                        else
                        {
                            int incValue = Mathf.RoundToInt((attackVerbRange - baseViewRange) * ((float)ticksStanding / ticksToSearch));

                            sightRange = (baseViewRange + incValue) * capacities.GetLevel(PawnCapacityDefOf.Sight);
                        }
                    }
                }
            }

            if (sightRange == 0f)
            {
                sightRange = baseViewRange * capacities.GetLevel(PawnCapacityDefOf.Sight);
            }

            if (!forTargeting && sleeping)
            {
                // Sleeping: sight reduced to 20% (if not for targeting).
                sightRange *= 0.2f;
            }
            // TODO: Apply moving penality?

            /*else if (!calcOnlyBase && pawnPather.Moving) {
             *      // When moving, sight reduced to 90%s.
             *      sightRange *= 0.9f;
             * }
             */

            // Check if standing on an affect view object.
            List <CompAffectVision> compsAffectVision = mapCompSeenFog.compAffectVisionGrid[(position.z * mapSizeX) + position.x];
            int compsCount = compsAffectVision.Count;

            for (int i = 0; i < compsCount; i++)
            {
                sightRange *= compsAffectVision[i].Props.fovMultiplier;
            }

            // Additional dark and weather debuff.
            if (!isMechanoid)
            {
                float currGlow = glowGrid.GameGlowAt(position);
                if (currGlow != 1f)
                {
                    float darkModifier = 0.6f;
                    // Each bionic eye reduce the dark debuff by 20.
                    int hediffsCount = hediffs.Count;
                    for (int i = 0; i < hediffsCount; i++)
                    {
                        if (hediffs[i].def == HediffDefOf.BionicEye)
                        {
                            darkModifier += 0.2f;
                        }
                    }

                    // Apply only if to debuff.
                    if (darkModifier < 1f)
                    {
                        // Adjusted to glow (100% full light - 60% dark).
                        sightRange *= Mathf.Lerp(darkModifier, 1f, currGlow);
                    }
                }

                if (!roofGrid.Roofed(position.x, position.z))
                {
                    float weatherFactor = weatherManager.CurWeatherAccuracyMultiplier;
                    if (weatherFactor != 1f)
                    {
                        // Weather factor is applied by half.
                        sightRange *= Mathf.Lerp(0.5f, 1f, weatherFactor);
                    }
                }
            }

            // Mininum sight.
            if (sightRange < 1f)
            {
                return(1);
            }

            return(sightRange);
        }