Exemple #1
0
        public static void AddVerbs(this VerbManager man, Hediff hediff)
        {
            if (man == null)
            {
                return;
            }
            if (Base.IsIgnoredMod(hediff?.def?.modContentPack?.Name))
            {
                return;
            }
            var comp = hediff.TryGetComp <HediffComp_VerbGiver>();

            if (comp?.VerbTracker?.AllVerbs == null)
            {
                return;
            }
            if (!Base.Features.HediffVerbs && !Base.IgnoredFeatures.HediffVerbs &&
                comp.VerbTracker.AllVerbs.Any(v => !v.IsMeleeAttack))
            {
                Log.ErrorOnce(
                    "[MVCF] Found a hediff with a ranged verb while that feature is not enabled. Enabling now. This is not recommend. Contant the author of " +
                    hediff?.def?.modContentPack?.Name + " and ask them to add a MVCF.ModDef.",
                    hediff?.def?.modContentPack?.Name?.GetHashCode() ?? -1);
                Base.Features.HediffVerbs = true;
                Base.ApplyPatches();
            }

            var extComp = comp as HediffComp_ExtendedVerbGiver;

            foreach (var verb in comp.VerbTracker.AllVerbs)
            {
                man.AddVerb(verb, VerbSource.Hediff, extComp?.PropsFor(verb));
            }
        }
Exemple #2
0
        public static void AddVerbs(this VerbManager man, ThingWithComps eq)
        {
            if (man == null)
            {
                return;
            }
            if (Base.IsIgnoredMod(eq?.def?.modContentPack?.Name))
            {
                return;
            }
            if (Compat.ShouldIgnore(eq))
            {
                return;
            }
            var comp = eq.TryGetComp <CompEquippable>();

            if (comp?.VerbTracker?.AllVerbs == null)
            {
                return;
            }
            if (!Base.Features.ExtraEquipmentVerbs && !Base.IgnoredFeatures.ExtraEquipmentVerbs &&
                comp.VerbTracker.AllVerbs.Count(v => !v.IsMeleeAttack) > 1)
            {
                Log.ErrorOnce(
                    "[MVCF] Found equipment with more than one ranged attack while that feature is not enabled. Enabling now. This is not recommend. Contact the author of " +
                    eq?.def?.modContentPack?.Name + " and ask them to add a MVCF.ModDef.",
                    eq?.def?.modContentPack?.Name?.GetHashCode() ?? -1);
                Base.Features.ExtraEquipmentVerbs = true;
                Base.ApplyPatches();
            }

            foreach (var verb in comp.VerbTracker.AllVerbs)
            {
                man.AddVerb(verb, VerbSource.Equipment, comp.props is CompProperties_VerbProps props
                    ? props.PropsFor(verb)
                    : eq.TryGetComp <Comp_VerbProps>()?.Props?.PropsFor(verb));
            }
        }
Exemple #3
0
        public static void AddVerbs(this VerbManager man, Apparel apparel)
        {
            if (man == null)
            {
                return;
            }
            if (Base.IsIgnoredMod(apparel?.def?.modContentPack?.Name))
            {
                return;
            }
            if (Compat.ShouldIgnore(apparel))
            {
                return;
            }
            var comp = apparel.TryGetComp <Comp_VerbGiver>();

            if (comp?.VerbTracker?.AllVerbs == null)
            {
                return;
            }
            if (!Base.Features.ApparelVerbs && !Base.IgnoredFeatures.ApparelVerbs)
            {
                Log.ErrorOnce(
                    "[MVCF] Found apparel with a verb while that feature is not enabled. Enabling now. This is not recommend. Contact the author of " +
                    apparel?.def?.modContentPack?.Name + " and ask them to add a MVCF.ModDef.",
                    apparel?.def?.modContentPack?.Name?.GetHashCode() ?? -1);
                Base.Features.ApparelVerbs = true;
                Base.ApplyPatches();
            }

            comp.Notify_Worn(man.Pawn);
            foreach (var verb in comp.VerbTracker.AllVerbs)
            {
                man.AddVerb(verb, VerbSource.Apparel, comp.PropsFor(verb));
            }
        }
Exemple #4
0
        public void Tick()
        {
            for (int i = 0; i < thingsToRegister.Count; i++)
            {
                BucketOf(thingsToRegister[i]).Add(thingsToRegister[i]);
            }
            thingsToRegister.Clear();
            for (int j = 0; j < thingsToDeregister.Count; j++)
            {
                BucketOf(thingsToDeregister[j]).Remove(thingsToDeregister[j]);
            }
            thingsToDeregister.Clear();
            if (DebugSettings.fastEcology)
            {
                Find.World.tileTemperatures.ClearCaches();
                for (int k = 0; k < thingLists.Count; k++)
                {
                    List <Thing> list = thingLists[k];
                    for (int l = 0; l < list.Count; l++)
                    {
                        if (list[l].def.category == ThingCategory.Plant)
                        {
                            list[l].TickLong();
                        }
                    }
                }
            }
            List <Thing> list2 = thingLists[Find.TickManager.TicksGame % TickInterval];

            for (int m = 0; m < list2.Count; m++)
            {
                if (!list2[m].Destroyed)
                {
                    try
                    {
                        switch (tickType)
                        {
                        case TickerType.Normal:
                            list2[m].Tick();
                            break;

                        case TickerType.Rare:
                            list2[m].TickRare();
                            break;

                        case TickerType.Long:
                            list2[m].TickLong();
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string text = (!list2[m].Spawned) ? string.Empty : (" (at " + list2[m].Position + ")");
                        if (Prefs.DevMode)
                        {
                            Log.Error("Exception ticking " + list2[m].ToStringSafe() + text + ": " + ex);
                        }
                        else
                        {
                            Log.ErrorOnce("Exception ticking " + list2[m].ToStringSafe() + text + ". Suppressing further errors. Exception: " + ex, list2[m].thingIDNumber ^ 0x22627165);
                        }
                    }
                }
            }
        }
        public static void BoolArray(ref bool[] arr, int elements, string label)
        {
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                if (arr.Length != elements)
                {
                    Log.ErrorOnce(string.Format("Bool array length mismatch for {0}", label), 74135877, false);
                }
                elements = arr.Length;
            }
            int num = (elements + 7) / 8;

            byte[] array = null;
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                array = new byte[num];
                int  num2 = 0;
                byte b    = 1;
                for (int i = 0; i < elements; i++)
                {
                    if (arr[i])
                    {
                        byte[] array2 = array;
                        int    num3   = num2;
                        array2[num3] |= b;
                    }
                    b *= 2;
                    if (b == 0)
                    {
                        b = 1;
                        num2++;
                    }
                }
            }
            DataExposeUtility.ByteArray(ref array, label);
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                if (arr == null)
                {
                    arr = new bool[elements];
                }
                if (array != null && array.Length != 0)
                {
                    if (array.Length != num)
                    {
                        int  num4 = 0;
                        byte b2   = 1;
                        for (int j = 0; j < elements; j++)
                        {
                            arr[j] = ((array[num4] & b2) != 0);
                            b2    *= 2;
                            if (b2 > 32)
                            {
                                b2 = 1;
                                num4++;
                            }
                        }
                    }
                    else
                    {
                        int  num5 = 0;
                        byte b3   = 1;
                        for (int k = 0; k < elements; k++)
                        {
                            arr[k] = ((array[num5] & b3) != 0);
                            b3    *= 2;
                            if (b3 == 0)
                            {
                                b3 = 1;
                                num5++;
                            }
                        }
                    }
                }
            }
        }
 public override void DrawWorker(Vector3 loc, Rot4 rot, ThingDef thingDef, Thing thing, float extraRotation)
 {
     Log.ErrorOnce("Graphic_Scatter cannot draw realtime.", 9432243);
 }
Exemple #7
0
        public static void BoolArray(ref bool[] arr, int elements, string label)
        {
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                if (arr.Length != elements)
                {
                    Log.ErrorOnce($"Bool array length mismatch for {label}", 74135877);
                }
                elements = arr.Length;
            }
            int num = (elements + 7) / 8;

            byte[] arr2 = null;
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                arr2 = new byte[num];
                int  num2 = 0;
                byte b    = 1;
                for (int i = 0; i < elements; i++)
                {
                    if (arr[i])
                    {
                        arr2[num2] |= b;
                    }
                    b = (byte)(b * 2);
                    if (b == 0)
                    {
                        b = 1;
                        num2++;
                    }
                }
            }
            ByteArray(ref arr2, label);
            if (Scribe.mode != LoadSaveMode.LoadingVars)
            {
                return;
            }
            if (arr == null)
            {
                arr = new bool[elements];
            }
            if (arr2 == null || arr2.Length == 0)
            {
                return;
            }
            if (arr2.Length != num)
            {
                int  num3 = 0;
                byte b2   = 1;
                for (int j = 0; j < elements; j++)
                {
                    arr[j] = ((arr2[num3] & b2) != 0);
                    b2     = (byte)(b2 * 2);
                    if (b2 > 32)
                    {
                        b2 = 1;
                        num3++;
                    }
                }
                return;
            }
            int  num4 = 0;
            byte b3   = 1;

            for (int k = 0; k < elements; k++)
            {
                arr[k] = ((arr2[num4] & b3) != 0);
                b3     = (byte)(b3 * 2);
                if (b3 == 0)
                {
                    b3 = 1;
                    num4++;
                }
            }
        }
Exemple #8
0
        public static TabRecord DrawTabs(Rect baseRect, IEnumerable <TabRecord> tabsEnum)
        {
            TabDrawer.tabList.Clear();
            foreach (TabRecord current in tabsEnum)
            {
                TabDrawer.tabList.Add(current);
            }
            TabRecord tabRecord  = null;
            TabRecord tabRecord2 = (from t in TabDrawer.tabList
                                    where t.selected
                                    select t).FirstOrDefault <TabRecord>();

            if (tabRecord2 == null)
            {
                Log.ErrorOnce("Drew tabs without any being selected.", 5509712);
                return(TabDrawer.tabList[0]);
            }
            float num      = baseRect.width + (float)(TabDrawer.tabList.Count - 1) * 10f;
            float tabWidth = num / (float)TabDrawer.tabList.Count;

            if (tabWidth > 200f)
            {
                tabWidth = 200f;
            }
            Rect position = new Rect(baseRect);

            position.y     -= 32f;
            position.height = 9999f;
            GUI.BeginGroup(position);
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            Func <TabRecord, Rect> func = delegate(TabRecord tab)
            {
                int   num2 = TabDrawer.tabList.IndexOf(tab);
                float x    = (float)num2 * (tabWidth - 10f);
                return(new Rect(x, 1f, tabWidth, 32f));
            };
            List <TabRecord> list = TabDrawer.tabList.ListFullCopy <TabRecord>();

            list.Remove(tabRecord2);
            list.Add(tabRecord2);
            TabRecord        tabRecord3 = null;
            List <TabRecord> list2      = list.ListFullCopy <TabRecord>();

            list2.Reverse();
            for (int i = 0; i < list2.Count; i++)
            {
                TabRecord tabRecord4 = list2[i];
                Rect      rect       = func(tabRecord4);
                if (tabRecord3 == null && Mouse.IsOver(rect))
                {
                    tabRecord3 = tabRecord4;
                }
                MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverTab);
                if (Widgets.ButtonInvisible(rect, false))
                {
                    tabRecord = tabRecord4;
                }
            }
            foreach (TabRecord current2 in list)
            {
                Rect rect2 = func(current2);
                current2.Draw(rect2);
            }
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
            if (tabRecord != null && tabRecord != tabRecord2)
            {
                SoundDefOf.RowTabSelect.PlayOneShotOnCamera(null);
                if (tabRecord.clickedAction != null)
                {
                    tabRecord.clickedAction();
                }
            }
            return(tabRecord);
        }
		public override void DoWindowContents(Rect inRect)
		{
			Text.Font = GameFont.Small;
			Rect rect;
			Rect outRect = rect = inRect.ContractedBy(4f);
			rect.xMax -= 33f;
			Rect rect2 = new Rect(0f, 0f, CategoryWidth, Text.CalcHeight("test", 1000f));
			Rect rect3 = new Rect(rect2.xMax, 0f, TitleWidth, rect2.height);
			Rect rect4 = new Rect(rect3.xMax, 0f, NumberWidth, rect2.height);
			Rect rect5 = new Rect(rect4.xMax, 0f, rect.width - rect4.xMax, rect2.height);
			Widgets.BeginScrollView(outRect, ref scrollPosition, new Rect(0f, 0f, rect.width, rect2.height * (float)tweakValueFields.Count));
			foreach (TweakInfo tweakValueField in tweakValueFields)
			{
				Widgets.Label(rect2, tweakValueField.tweakValue.category);
				Widgets.Label(rect3, $"{tweakValueField.field.DeclaringType.Name}.{tweakValueField.field.Name}");
				float num;
				bool flag;
				if (tweakValueField.field.FieldType == typeof(float) || tweakValueField.field.FieldType == typeof(int) || tweakValueField.field.FieldType == typeof(ushort))
				{
					float asFloat = GetAsFloat(tweakValueField.field);
					num = Widgets.HorizontalSlider(rect5, GetAsFloat(tweakValueField.field), tweakValueField.tweakValue.min, tweakValueField.tweakValue.max);
					SetFromFloat(tweakValueField.field, num);
					flag = (asFloat != num);
				}
				else if (tweakValueField.field.FieldType == typeof(bool))
				{
					bool num2 = (bool)tweakValueField.field.GetValue(null);
					bool checkOn = num2;
					Widgets.Checkbox(rect5.xMin, rect5.yMin, ref checkOn);
					tweakValueField.field.SetValue(null, checkOn);
					num = (checkOn ? 1 : 0);
					flag = (num2 != checkOn);
				}
				else
				{
					Log.ErrorOnce($"Attempted to tweakvalue unknown field type {tweakValueField.field.FieldType}", 83944645);
					flag = false;
					num = tweakValueField.initial;
				}
				if (num != tweakValueField.initial)
				{
					GUI.color = Color.red;
					Widgets.Label(rect4, $"{tweakValueField.initial} -> {num}");
					GUI.color = Color.white;
					if (Widgets.ButtonInvisible(rect4))
					{
						flag = true;
						if (tweakValueField.field.FieldType == typeof(float) || tweakValueField.field.FieldType == typeof(int) || tweakValueField.field.FieldType == typeof(ushort))
						{
							SetFromFloat(tweakValueField.field, tweakValueField.initial);
						}
						else if (tweakValueField.field.FieldType == typeof(bool))
						{
							tweakValueField.field.SetValue(null, tweakValueField.initial != 0f);
						}
						else
						{
							Log.ErrorOnce($"Attempted to tweakvalue unknown field type {tweakValueField.field.FieldType}", 83944646);
						}
					}
				}
				else
				{
					Widgets.Label(rect4, $"{tweakValueField.initial}");
				}
				if (flag)
				{
					MethodInfo method = tweakValueField.field.DeclaringType.GetMethod(tweakValueField.field.Name + "_Changed", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						method.Invoke(null, null);
					}
				}
				rect2.y += rect2.height;
				rect3.y += rect2.height;
				rect4.y += rect2.height;
				rect5.y += rect2.height;
			}
			Widgets.EndScrollView();
		}
Exemple #10
0
        public override void DoWindowContents(Rect inRect)
        {
            Text.Font = GameFont.Small;
            Rect rect  = inRect.ContractedBy(4f);
            Rect rect2 = rect;

            rect2.xMax -= 33f;
            Rect rect3 = new Rect(0f, 0f, EditWindow_TweakValues.CategoryWidth, Text.CalcHeight("test", 1000f));
            Rect rect4 = new Rect(rect3.xMax, 0f, EditWindow_TweakValues.TitleWidth, rect3.height);
            Rect rect5 = new Rect(rect4.xMax, 0f, EditWindow_TweakValues.NumberWidth, rect3.height);
            Rect rect6 = new Rect(rect5.xMax, 0f, rect2.width - rect5.xMax, rect3.height);

            Widgets.BeginScrollView(rect, ref this.scrollPosition, new Rect(0f, 0f, rect2.width, rect3.height * (float)EditWindow_TweakValues.tweakValueFields.Count), true);
            foreach (EditWindow_TweakValues.TweakInfo tweakInfo in EditWindow_TweakValues.tweakValueFields)
            {
                Widgets.Label(rect3, tweakInfo.tweakValue.category);
                Widgets.Label(rect4, string.Format("{0}.{1}", tweakInfo.field.DeclaringType.Name, tweakInfo.field.Name));
                float num;
                bool  flag;
                if (tweakInfo.field.FieldType == typeof(float) || tweakInfo.field.FieldType == typeof(int) || tweakInfo.field.FieldType == typeof(ushort))
                {
                    float asFloat = this.GetAsFloat(tweakInfo.field);
                    num = Widgets.HorizontalSlider(rect6, this.GetAsFloat(tweakInfo.field), tweakInfo.tweakValue.min, tweakInfo.tweakValue.max, false, null, null, null, -1f);
                    this.SetFromFloat(tweakInfo.field, num);
                    flag = (asFloat != num);
                }
                else if (tweakInfo.field.FieldType == typeof(bool))
                {
                    bool flag2 = (bool)tweakInfo.field.GetValue(null);
                    bool flag3 = flag2;
                    Widgets.Checkbox(rect6.xMin, rect6.yMin, ref flag3, 24f, false, false, null, null);
                    tweakInfo.field.SetValue(null, flag3);
                    num  = (float)((!flag3) ? 0 : 1);
                    flag = (flag2 != flag3);
                }
                else
                {
                    Log.ErrorOnce(string.Format("Attempted to tweakvalue unknown field type {0}", tweakInfo.field.FieldType), 83944645, false);
                    flag = false;
                    num  = tweakInfo.initial;
                }
                if (num != tweakInfo.initial)
                {
                    GUI.color = Color.red;
                    Widgets.Label(rect5, string.Format("{0} -> {1}", tweakInfo.initial, num));
                    GUI.color = Color.white;
                    if (Widgets.ButtonInvisible(rect5, false))
                    {
                        flag = true;
                        if (tweakInfo.field.FieldType == typeof(float) || tweakInfo.field.FieldType == typeof(int) || tweakInfo.field.FieldType == typeof(ushort))
                        {
                            this.SetFromFloat(tweakInfo.field, tweakInfo.initial);
                        }
                        else if (tweakInfo.field.FieldType == typeof(bool))
                        {
                            tweakInfo.field.SetValue(null, tweakInfo.initial != 0f);
                        }
                        else
                        {
                            Log.ErrorOnce(string.Format("Attempted to tweakvalue unknown field type {0}", tweakInfo.field.FieldType), 83944646, false);
                        }
                    }
                }
                else
                {
                    Widgets.Label(rect5, string.Format("{0}", tweakInfo.initial));
                }
                if (flag)
                {
                    MethodInfo method = tweakInfo.field.DeclaringType.GetMethod(tweakInfo.field.Name + "_Changed", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    if (method != null)
                    {
                        method.Invoke(null, null);
                    }
                }
                rect3.y += rect3.height;
                rect4.y += rect3.height;
                rect5.y += rect3.height;
                rect6.y += rect3.height;
            }
            Widgets.EndScrollView();
        }
Exemple #11
0
        private bool CheckCellBasedReachability(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams)
        {
            IntVec3 foundCell = IntVec3.Invalid;

            Region[]    directRegionGrid = regionGrid.DirectGrid;
            PathGrid    pathGrid         = map.pathGrid;
            CellIndices cellIndices      = map.cellIndices;

            map.floodFiller.FloodFill(start, delegate(IntVec3 c)
            {
                int num = cellIndices.CellToIndex(c);
                if ((traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) && c.GetTerrain(map).IsWater)
                {
                    return(false);
                }
                if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    if (!pathGrid.WalkableFast(num))
                    {
                        Building edifice = c.GetEdifice(map);
                        if (edifice == null || !PathFinder.IsDestroyable(edifice))
                        {
                            return(false);
                        }
                    }
                }
                else if (traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater)
                {
                    Log.ErrorOnce("Do not use this method for non-cell based modes!", 938476762);
                    if (!pathGrid.WalkableFast(num))
                    {
                        return(false);
                    }
                }
                Region region = directRegionGrid[num];
                if (region != null && !region.Allows(traverseParams, isDestination: false))
                {
                    return(false);
                }
                return(true);
            }, delegate(IntVec3 c)
            {
                if (ReachabilityImmediate.CanReachImmediate(c, dest, map, peMode, traverseParams.pawn))
                {
                    foundCell = c;
                    return(true);
                }
                return(false);
            });
            if (foundCell.IsValid)
            {
                if (CanUseCache(traverseParams.mode))
                {
                    Region validRegionAt = regionGrid.GetValidRegionAt(foundCell);
                    if (validRegionAt != null)
                    {
                        for (int i = 0; i < startingRegions.Count; i++)
                        {
                            cache.AddCachedResult(startingRegions[i].Room, validRegionAt.Room, traverseParams, reachable: true);
                        }
                    }
                }
                return(true);
            }
            if (CanUseCache(traverseParams.mode))
            {
                for (int j = 0; j < startingRegions.Count; j++)
                {
                    for (int k = 0; k < destRegions.Count; k++)
                    {
                        cache.AddCachedResult(startingRegions[j].Room, destRegions[k].Room, traverseParams, reachable: false);
                    }
                }
            }
            return(false);
        }
Exemple #12
0
        public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams)
        {
            if (working)
            {
                Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233);
                return(false);
            }
            if (traverseParams.pawn != null)
            {
                if (!traverseParams.pawn.Spawned)
                {
                    return(false);
                }
                if (traverseParams.pawn.Map != map)
                {
                    Log.Error("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=" + traverseParams.pawn + " pawn.Map=" + traverseParams.pawn.Map + " map=" + map);
                    return(false);
                }
            }
            if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn))
            {
                return(true);
            }
            if (!dest.IsValid)
            {
                return(false);
            }
            if (dest.HasThing && dest.Thing.Map != map)
            {
                return(false);
            }
            if (start.InBounds(map) && dest.Cell.InBounds(map))
            {
                if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    Room room = RegionAndRoomQuery.RoomAtFast(start, map);
                    if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map))
                    {
                        return(true);
                    }
                }
                if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
                {
                    TraverseParms traverseParams2 = traverseParams;
                    traverseParams2.mode = TraverseMode.PassDoors;
                    if (CanReach(start, dest, peMode, traverseParams2))
                    {
                        return(true);
                    }
                }
                dest    = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode);
                working = true;
                try
                {
                    pathGrid   = map.pathGrid;
                    regionGrid = map.regionGrid;
                    reachedIndex++;
                    destRegions.Clear();
                    switch (peMode)
                    {
                    case PathEndMode.OnCell:
                    {
                        Region region = dest.Cell.GetRegion(map);
                        if (region != null && region.Allows(traverseParams, isDestination: true))
                        {
                            destRegions.Add(region);
                        }
                        break;
                    }

                    case PathEndMode.Touch:
                        TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions);
                        break;
                    }
                    if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                    {
                        FinalizeCheck();
                        return(false);
                    }
                    destRegions.RemoveDuplicates();
                    openQueue.Clear();
                    numRegionsOpened = 0;
                    DetermineStartRegions(start);
                    if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                    {
                        FinalizeCheck();
                        return(false);
                    }
                    if (startingRegions.Any() && destRegions.Any() && CanUseCache(traverseParams.mode))
                    {
                        switch (GetCachedResult(traverseParams))
                        {
                        case BoolUnknown.True:
                            FinalizeCheck();
                            return(true);

                        case BoolUnknown.False:
                            FinalizeCheck();
                            return(false);
                        }
                    }
                    if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater)
                    {
                        bool result = CheckCellBasedReachability(start, dest, peMode, traverseParams);
                        FinalizeCheck();
                        return(result);
                    }
                    bool result2 = CheckRegionBasedReachability(traverseParams);
                    FinalizeCheck();
                    return(result2);
                }
                finally
                {
                    working = false;
                }
            }
            return(false);
        }
Exemple #13
0
        public static Thing RegionwiseBFSWorker(IntVec3 root, Map map, ThingRequest req, PathEndMode peMode, TraverseParms traverseParams, Predicate <Thing> validator, Func <Thing, float> priorityGetter, int minRegions, int maxRegions, float maxDistance, out int regionsSeen, RegionType traversableRegionTypes = RegionType.Set_Passable, bool ignoreEntirelyForbiddenRegions = false)
        {
            regionsSeen = 0;
            Thing result;

            if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
            {
                Log.Error("RegionwiseBFSWorker with traverseParams.mode PassAllDestroyableThings. Use ClosestThingGlobal.", false);
                result = null;
            }
            else if (traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater)
            {
                Log.Error("RegionwiseBFSWorker with traverseParams.mode PassAllDestroyableThingsNotWater. Use ClosestThingGlobal.", false);
                result = null;
            }
            else if (!req.IsUndefined && !req.CanBeFoundInRegion)
            {
                Log.ErrorOnce("RegionwiseBFSWorker with thing request group " + req.group + ". This group is never stored in regions. Most likely a global search should have been used.", 385766189, false);
                result = null;
            }
            else
            {
                Region region = root.GetRegion(map, traversableRegionTypes);
                if (region == null)
                {
                    result = null;
                }
                else
                {
                    float maxDistSquared = maxDistance * maxDistance;
                    RegionEntryPredicate entryCondition = (Region from, Region to) => to.Allows(traverseParams, false) && (maxDistance > 5000f || to.extentsClose.ClosestDistSquaredTo(root) < maxDistSquared);
                    Thing           closestThing        = null;
                    float           closestDistSquared  = 9999999f;
                    float           bestPrio            = float.MinValue;
                    int             regionsSeenScan     = 0;
                    RegionProcessor regionProcessor     = delegate(Region r)
                    {
                        regionsSeenScan++;
                        bool result2;
                        if (r.portal == null && !r.Allows(traverseParams, true))
                        {
                            result2 = false;
                        }
                        else
                        {
                            if (!ignoreEntirelyForbiddenRegions || !r.IsForbiddenEntirely(traverseParams.pawn))
                            {
                                List <Thing> list = r.ListerThings.ThingsMatching(req);
                                for (int i = 0; i < list.Count; i++)
                                {
                                    Thing thing = list[i];
                                    if (ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, peMode, traverseParams.pawn))
                                    {
                                        float num = (priorityGetter == null) ? 0f : priorityGetter(thing);
                                        if (num >= bestPrio)
                                        {
                                            float num2 = (float)(thing.Position - root).LengthHorizontalSquared;
                                            if ((num > bestPrio || num2 < closestDistSquared) && num2 < maxDistSquared)
                                            {
                                                if (validator == null || validator(thing))
                                                {
                                                    closestThing       = thing;
                                                    closestDistSquared = num2;
                                                    bestPrio           = num;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            result2 = (regionsSeenScan >= minRegions && closestThing != null);
                        }
                        return(result2);
                    };
                    RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, maxRegions, traversableRegionTypes);
                    regionsSeen = regionsSeenScan;
                    result      = closestThing;
                }
            }
            return(result);
        }
Exemple #14
0
        public void Tick()
        {
            for (int i = 0; i < this.thingsToRegister.Count; i++)
            {
                this.BucketOf(this.thingsToRegister[i]).Add(this.thingsToRegister[i]);
            }
            this.thingsToRegister.Clear();
            for (int j = 0; j < this.thingsToDeregister.Count; j++)
            {
                this.BucketOf(this.thingsToDeregister[j]).Remove(this.thingsToDeregister[j]);
            }
            this.thingsToDeregister.Clear();
            if (DebugSettings.fastEcology)
            {
                Find.World.tileTemperatures.ClearCaches();
                for (int k = 0; k < this.thingLists.Count; k++)
                {
                    List <Thing> list = this.thingLists[k];
                    for (int l = 0; l < list.Count; l++)
                    {
                        if (list[l].def.category == ThingCategory.Plant)
                        {
                            list[l].TickLong();
                        }
                    }
                }
            }
            List <Thing> list2 = this.thingLists[Find.TickManager.TicksGame % this.TickInterval];

            for (int m = 0; m < list2.Count; m++)
            {
                if (!list2[m].Destroyed)
                {
                    try
                    {
                        TickerType tickerType = this.tickType;
                        if (tickerType != TickerType.Normal)
                        {
                            if (tickerType != TickerType.Rare)
                            {
                                if (tickerType == TickerType.Long)
                                {
                                    list2[m].TickLong();
                                }
                            }
                            else
                            {
                                list2[m].TickRare();
                            }
                        }
                        else
                        {
                            list2[m].Tick();
                        }
                    }
                    catch (Exception ex)
                    {
                        string text = (!list2[m].Spawned) ? string.Empty : (" (at " + list2[m].Position + ")");
                        if (Prefs.DevMode)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Exception ticking ",
                                list2[m].ToStringSafe <Thing>(),
                                text,
                                ": ",
                                ex
                            }), false);
                        }
                        else
                        {
                            Log.ErrorOnce(string.Concat(new object[]
                            {
                                "Exception ticking ",
                                list2[m].ToStringSafe <Thing>(),
                                text,
                                ". Suppressing further errors. Exception: ",
                                ex
                            }), list2[m].thingIDNumber ^ 576876901, false);
                        }
                    }
                }
            }
        }